Aucune description

main.dart 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import 'package:flutter/material.dart';
  2. import 'package:photo/photo.dart';
  3. import 'package:photo_manager/photo_manager.dart';
  4. void main() => runApp(new MyApp());
  5. class MyApp extends StatelessWidget {
  6. // This widget is the root of your application.
  7. @override
  8. Widget build(BuildContext context) {
  9. return new MaterialApp(
  10. title: 'Pick Image Demo',
  11. theme: new ThemeData(
  12. primarySwatch: Colors.blue,
  13. ),
  14. home: new MyHomePage(title: 'Pick Image Demo'),
  15. );
  16. }
  17. }
  18. class MyHomePage extends StatefulWidget {
  19. MyHomePage({Key key, this.title}) : super(key: key);
  20. final String title;
  21. @override
  22. _MyHomePageState createState() => new _MyHomePageState();
  23. }
  24. class _MyHomePageState extends State<MyHomePage> {
  25. String currentSelected = "";
  26. void _pickImage() async {
  27. List<ImageEntity> imgList = await PhotoPicker.pickImage(
  28. context: context, // BuildContext requied
  29. /// The following are optional parameters.
  30. themeColor: Colors.green, // the title color and bottom color
  31. padding: 1.0, // item padding
  32. dividerColor: Colors.deepOrange, // divider color
  33. disableColor: Colors.grey.shade300, // the check box disable color
  34. itemRadio: 0.88, // the content item radio
  35. maxSelected: 8, // max picker image count
  36. provider: I18nProvider.chinese, // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
  37. rowCount: 5, // item row count
  38. textColor: Colors.white, // text color
  39. thumbSize: 150, // preview thumb size , default is 64
  40. sortDelegate: SortDelegate.common, // default is common ,or you make custom delegate to sort your gallery
  41. checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(), // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
  42. );
  43. if (imgList == null) {
  44. currentSelected = "not select item";
  45. } else {
  46. List<String> r = [];
  47. for (var e in imgList) {
  48. var file = await e.file;
  49. r.add(file.absolute.path);
  50. }
  51. currentSelected = r.join("\n\n");
  52. }
  53. setState(() {});
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. return new Scaffold(
  58. appBar: new AppBar(
  59. title: new Text(widget.title),
  60. ),
  61. body: Container(
  62. child: Center(
  63. child: Text(
  64. '$currentSelected',
  65. textAlign: TextAlign.center,
  66. ),
  67. ),
  68. ),
  69. floatingActionButton: new FloatingActionButton(
  70. onPressed: _pickImage,
  71. tooltip: 'pickImage',
  72. child: new Icon(Icons.add),
  73. ),
  74. );
  75. }
  76. }