Bez popisu

main.dart 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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: 5.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: CNProvider(), // 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. );
  42. if (imgList == null) {
  43. currentSelected = "not select item";
  44. } else {
  45. List<String> r = [];
  46. for (var e in imgList) {
  47. var file = await e.file;
  48. r.add(file.absolute.path);
  49. }
  50. currentSelected = r.join("\n\n");
  51. }
  52. setState(() {});
  53. }
  54. @override
  55. Widget build(BuildContext context) {
  56. return new Scaffold(
  57. appBar: new AppBar(
  58. title: new Text(widget.title),
  59. ),
  60. body: Container(
  61. child: Center(
  62. child: Text(
  63. '$currentSelected',
  64. textAlign: TextAlign.center,
  65. ),
  66. ),
  67. ),
  68. floatingActionButton: new FloatingActionButton(
  69. onPressed: _pickImage,
  70. tooltip: 'pickImage',
  71. child: new Icon(Icons.add),
  72. ),
  73. );
  74. }
  75. }