forked from lxm_tools/flutter-picgo
feature:编写使用ImagePicker获取图片到对话框预览
This commit is contained in:
Binary file not shown.
86
lib/components/picker_image.dart
Normal file
86
lib/components/picker_image.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 图片选择预览Dialog
|
||||
class PickerImageDialog extends Dialog {
|
||||
final String imageName;
|
||||
final String imagePath;
|
||||
|
||||
PickerImageDialog(this.imageName, this.imagePath);
|
||||
|
||||
TextEditingController _controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_controller = TextEditingController(text: imageName);
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
height: 280.0,
|
||||
width: double.infinity,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(25, 0, 25, 0),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
height: 180,
|
||||
width: double.infinity,
|
||||
child: Image.file(File(this.imagePath), fit: BoxFit.cover),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: 40,
|
||||
),
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: "请输入图片名称,注意保留后缀",
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Container(
|
||||
height: 30,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: RaisedButton(
|
||||
color: Theme.of(context).accentColor,
|
||||
textColor: Colors.white,
|
||||
child: Text('取消'),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: RaisedButton(
|
||||
color: Theme.of(context).accentColor,
|
||||
textColor: Colors.white,
|
||||
child: Text('上传'),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,17 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_picgo/components/picker_image.dart';
|
||||
import 'package:flutter_picgo/model/uploaded.dart';
|
||||
import 'package:flutter_picgo/views/album_page/album_page_presenter.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class AlbumPage extends StatelessWidget {
|
||||
class AlbumPage extends StatefulWidget {
|
||||
@override
|
||||
_AlbumPageState createState() => _AlbumPageState();
|
||||
}
|
||||
|
||||
class _AlbumPageState extends State<AlbumPage> implements AlbumPageContract {
|
||||
final picker = ImagePicker();
|
||||
|
||||
@override
|
||||
@@ -13,7 +22,7 @@ class AlbumPage extends StatelessWidget {
|
||||
centerTitle: true,
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.file_upload),
|
||||
child: Icon(IconData(0xe639, fontFamily: 'iconfont')),
|
||||
onPressed: () {
|
||||
getImage();
|
||||
},
|
||||
@@ -24,9 +33,18 @@ class AlbumPage extends StatelessWidget {
|
||||
void getImage() async {
|
||||
try {
|
||||
final pickedFile = await picker.getImage(source: ImageSource.gallery);
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return PickerImageDialog('dasdasd.png', pickedFile.path);
|
||||
});
|
||||
File(pickedFile.path);
|
||||
} catch (e) {
|
||||
print('报错$e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void loadUploadedImages(List<Uploaded> uploadeds) {}
|
||||
}
|
||||
27
lib/views/album_page/album_page_presenter.dart
Normal file
27
lib/views/album_page/album_page_presenter.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter_picgo/model/uploaded.dart';
|
||||
import 'package:flutter_picgo/resources/table_name_keys.dart';
|
||||
import 'package:flutter_picgo/utils/sql.dart';
|
||||
|
||||
abstract class AlbumPageContract {
|
||||
|
||||
void loadUploadedImages(List<Uploaded> uploadeds);
|
||||
|
||||
}
|
||||
|
||||
class AlbumPagePresenter {
|
||||
|
||||
AlbumPageContract _view;
|
||||
|
||||
AlbumPagePresenter(this._view);
|
||||
|
||||
doLoadUploadedImages() {
|
||||
var sql = Sql.setTable(TABLE_NAME_UPLOADED);
|
||||
|
||||
}
|
||||
|
||||
doUploadImage(File imgFile) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user