Aucune description

main.dart 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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<AssetEntity> 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.grey, // 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
  37. .chinese, // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
  38. rowCount: 5, // item row count
  39. textColor: Colors.white, // text color
  40. thumbSize: 150, // preview thumb size , default is 64
  41. sortDelegate: SortDelegate
  42. .common, // default is common ,or you make custom delegate to sort your gallery
  43. checkBoxBuilderDelegate:
  44. DefaultCheckBoxBuilderDelegate(
  45. activeColor: Colors.white,
  46. unselectedColor: Colors.white,
  47. ), // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
  48. );
  49. if (imgList == null) {
  50. currentSelected = "not select item";
  51. } else {
  52. List<String> r = [];
  53. for (var e in imgList) {
  54. var file = await e.file;
  55. r.add(file.absolute.path);
  56. }
  57. currentSelected = r.join("\n\n");
  58. }
  59. setState(() {});
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. return new Scaffold(
  64. appBar: new AppBar(
  65. title: new Text(widget.title),
  66. ),
  67. body: Container(
  68. child: Center(
  69. child: Text(
  70. '$currentSelected',
  71. textAlign: TextAlign.center,
  72. ),
  73. ),
  74. ),
  75. floatingActionButton: new FloatingActionButton(
  76. onPressed: _pickImage,
  77. tooltip: 'pickImage',
  78. child: new Icon(Icons.add),
  79. ),
  80. );
  81. }
  82. }