Brak opisu

main.dart 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.chinese,
  45. // i18n provider ,default is chinese. , you can custom I18nProvider or use ENProvider()
  46. rowCount: 3,
  47. // item row count
  48. textColor: Colors.white,
  49. // text color
  50. thumbSize: 150,
  51. // preview thumb size , default is 64
  52. sortDelegate: SortDelegate.common,
  53. // default is common ,or you make custom delegate to sort your gallery
  54. checkBoxBuilderDelegate: DefaultCheckBoxBuilderDelegate(
  55. activeColor: Colors.white,
  56. unselectedColor: Colors.white,
  57. ),
  58. // default is DefaultCheckBoxBuilderDelegate ,or you make custom delegate to create checkbox
  59. loadingDelegate: this,
  60. // if you want to build custom loading widget,extends LoadingDelegate, [see example/lib/main.dart]
  61. badgeDelegate: const DurationBadgeDelegate(),
  62. );
  63. if (imgList == null) {
  64. currentSelected = "not select item";
  65. } else {
  66. List<String> r = [];
  67. for (var e in imgList) {
  68. var file = await e.file;
  69. r.add(file.absolute.path);
  70. }
  71. currentSelected = r.join("\n\n");
  72. }
  73. setState(() {});
  74. }
  75. @override
  76. Widget buildBigImageLoading(
  77. BuildContext context, AssetEntity entity, Color themeColor) {
  78. return Center(
  79. child: Container(
  80. width: 50.0,
  81. height: 50.0,
  82. child: CupertinoActivityIndicator(
  83. radius: 25.0,
  84. ),
  85. ),
  86. );
  87. }
  88. @override
  89. Widget buildPreviewLoading(
  90. BuildContext context, AssetEntity entity, Color themeColor) {
  91. return Center(
  92. child: Container(
  93. width: 50.0,
  94. height: 50.0,
  95. child: CupertinoActivityIndicator(
  96. radius: 25.0,
  97. ),
  98. ),
  99. );
  100. }
  101. @override
  102. Widget build(BuildContext context) {
  103. return new Scaffold(
  104. appBar: new AppBar(
  105. title: new Text(widget.title),
  106. ),
  107. body: Container(
  108. child: Center(
  109. child: Text(
  110. '$currentSelected',
  111. textAlign: TextAlign.center,
  112. ),
  113. ),
  114. ),
  115. floatingActionButton: new FloatingActionButton(
  116. onPressed: _pickImage,
  117. tooltip: 'pickImage',
  118. child: new Icon(Icons.add),
  119. ),
  120. );
  121. }
  122. }