Bez popisu

main.dart 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:photo/photo.dart';
  4. import 'package:photo_manager/photo_manager.dart';
  5. void main() => runApp(new MyApp());
  6. class MyApp extends StatelessWidget {
  7. // This widget is the root of your application.
  8. @override
  9. Widget build(BuildContext context) {
  10. return new MaterialApp(
  11. title: 'Pick Image Demo',
  12. theme: new ThemeData(
  13. primarySwatch: Colors.blue,
  14. ),
  15. home: new MyHomePage(title: 'Pick Image Demo'),
  16. );
  17. }
  18. }
  19. class MyHomePage extends StatefulWidget {
  20. MyHomePage({Key key, this.title}) : super(key: key);
  21. final String title;
  22. @override
  23. _MyHomePageState createState() => new _MyHomePageState();
  24. }
  25. class _MyHomePageState extends State<MyHomePage> with LoadingDelegate {
  26. String currentSelected = "";
  27. void _pickImage() async {
  28. List<AssetEntity> imgList = await PhotoPicker.pickAsset(
  29. // BuildContext required
  30. context: context,
  31. /// The following are optional parameters.
  32. themeColor: Colors.green,
  33. // the title color and bottom color
  34. padding: 1.0,
  35. // item padding
  36. dividerColor: Colors.grey,
  37. // divider color
  38. disableColor: Colors.grey.shade300,
  39. // the check box disable color
  40. itemRadio: 0.88,
  41. // the content item radio
  42. maxSelected: 8,
  43. // max picker image count
  44. provider: I18nProvider.english,
  45. // provider: I18nProvider.chinese,
  46. // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
  47. rowCount: 3,
  48. // item row count
  49. textColor: Colors.white,
  50. // text color
  51. thumbSize: 150,
  52. // preview thumb size , default is 64
  53. sortDelegate: SortDelegate.common,
  54. // default is common ,or you make custom delegate to sort your gallery
  55. checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(
  56. activeColor: Colors.white,
  57. unselectedColor: Colors.white,
  58. ),
  59. // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
  60. loadingDelegate: this,
  61. // if you want to build custom loading widget,extends LoadingDelegate, [see example/lib/main.dart]
  62. badgeDelegate: const DurationBadgeDelegate(),
  63. );
  64. if (imgList == null) {
  65. currentSelected = "not select item";
  66. } else {
  67. List<String> r = [];
  68. for (var e in imgList) {
  69. var file = await e.file;
  70. r.add(file.absolute.path);
  71. }
  72. currentSelected = r.join("\n\n");
  73. }
  74. setState(() {});
  75. }
  76. @override
  77. Widget buildBigImageLoading(
  78. BuildContext context, AssetEntity entity, Color themeColor) {
  79. return Center(
  80. child: Container(
  81. width: 50.0,
  82. height: 50.0,
  83. child: CupertinoActivityIndicator(
  84. radius: 25.0,
  85. ),
  86. ),
  87. );
  88. }
  89. @override
  90. Widget buildPreviewLoading(
  91. BuildContext context, AssetEntity entity, Color themeColor) {
  92. return Center(
  93. child: Container(
  94. width: 50.0,
  95. height: 50.0,
  96. child: CupertinoActivityIndicator(
  97. radius: 25.0,
  98. ),
  99. ),
  100. );
  101. }
  102. @override
  103. Widget build(BuildContext context) {
  104. return new Scaffold(
  105. appBar: new AppBar(
  106. title: new Text(widget.title),
  107. ),
  108. body: Container(
  109. child: Center(
  110. child: Text(
  111. '$currentSelected',
  112. textAlign: TextAlign.center,
  113. ),
  114. ),
  115. ),
  116. floatingActionButton: new FloatingActionButton(
  117. onPressed: _pickImage,
  118. tooltip: 'pickImage',
  119. child: new Icon(Icons.add),
  120. ),
  121. );
  122. }
  123. }