Showing
2 changed files
with
83 additions
and
2 deletions
| 1 | +import 'dart:io'; | ||
| 2 | + | ||
| 1 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 2 | import 'package:Parlando/extension/int_extension.dart'; | 4 | import 'package:Parlando/extension/int_extension.dart'; |
| 3 | import 'package:Parlando/widgets/my_app_bar.dart'; | 5 | import 'package:Parlando/widgets/my_app_bar.dart'; |
| 4 | import 'package:flutter_gen/gen_l10n/Parlando_localizations.dart'; | 6 | import 'package:flutter_gen/gen_l10n/Parlando_localizations.dart'; |
| 7 | +import 'package:image_picker/image_picker.dart'; | ||
| 5 | 8 | ||
| 6 | class AccountEditPage extends StatefulWidget { | 9 | class AccountEditPage extends StatefulWidget { |
| 7 | const AccountEditPage({Key? key}) : super(key: key); | 10 | const AccountEditPage({Key? key}) : super(key: key); |
| ... | @@ -66,13 +69,60 @@ class MapScreenState extends State<AccountEditPage> | ... | @@ -66,13 +69,60 @@ class MapScreenState extends State<AccountEditPage> |
| 66 | child: Row( | 69 | child: Row( |
| 67 | mainAxisAlignment: MainAxisAlignment.center, | 70 | mainAxisAlignment: MainAxisAlignment.center, |
| 68 | children: <Widget>[ | 71 | children: <Widget>[ |
| 69 | - CircleAvatar( | 72 | + InkWell( |
| 73 | + child: CircleAvatar( | ||
| 70 | backgroundColor: Colors.red, | 74 | backgroundColor: Colors.red, |
| 71 | radius: 25.px, | 75 | radius: 25.px, |
| 72 | child: const Icon( | 76 | child: const Icon( |
| 73 | Icons.camera_alt, | 77 | Icons.camera_alt, |
| 74 | color: Colors.white, | 78 | color: Colors.white, |
| 75 | ), | 79 | ), |
| 80 | + ), | ||
| 81 | + onTap: () { | ||
| 82 | + showModalBottomSheet( | ||
| 83 | + context: context, | ||
| 84 | + builder: (context) { | ||
| 85 | + return Column( | ||
| 86 | + mainAxisSize: MainAxisSize.min, | ||
| 87 | + children: <Widget>[ | ||
| 88 | + ListTile( | ||
| 89 | + title: const Center( | ||
| 90 | + child: Text( | ||
| 91 | + '拍照', | ||
| 92 | + style: TextStyle( | ||
| 93 | + fontSize: 18, | ||
| 94 | + ), | ||
| 95 | + ), | ||
| 96 | + ), | ||
| 97 | + onTap: () { | ||
| 98 | + _getImage(); | ||
| 99 | + }, | ||
| 100 | + ), | ||
| 101 | + ListTile( | ||
| 102 | + title: const Center( | ||
| 103 | + child: Text( | ||
| 104 | + '相册', | ||
| 105 | + style: TextStyle( | ||
| 106 | + fontSize: 18, | ||
| 107 | + ), | ||
| 108 | + ), | ||
| 109 | + ), | ||
| 110 | + onTap: () { | ||
| 111 | + onImageButtonPressed( | ||
| 112 | + ImageSource.gallery, context: context, | ||
| 113 | + capturedImageFile: (s) { | ||
| 114 | + print("file path ${s}"); | ||
| 115 | + setState(() { | ||
| 116 | + // _imageFile = s; | ||
| 117 | + }); | ||
| 118 | + }, | ||
| 119 | + ); | ||
| 120 | + }, | ||
| 121 | + ), | ||
| 122 | + ], | ||
| 123 | + ); | ||
| 124 | + }); | ||
| 125 | + }, | ||
| 76 | ) | 126 | ) |
| 77 | ], | 127 | ], |
| 78 | )), | 128 | )), |
| ... | @@ -412,3 +462,33 @@ class MapScreenState extends State<AccountEditPage> | ... | @@ -412,3 +462,33 @@ class MapScreenState extends State<AccountEditPage> |
| 412 | ); | 462 | ); |
| 413 | } | 463 | } |
| 414 | } | 464 | } |
| 465 | + | ||
| 466 | +onImageButtonPressed(ImageSource source, | ||
| 467 | + {required BuildContext context, capturedImageFile}) async { | ||
| 468 | + final ImagePicker _picker = ImagePicker(); | ||
| 469 | + File val; | ||
| 470 | + | ||
| 471 | + final pickedFile = await _picker.pickImage( | ||
| 472 | + source: source, | ||
| 473 | + ); | ||
| 474 | + | ||
| 475 | + val = await ImageCropper.cropImage( | ||
| 476 | + sourcePath: pickedFile.path, | ||
| 477 | + aspectRatio: CropAspectRatio(ratioX: 1, ratioY: 1), | ||
| 478 | + compressQuality: 100, | ||
| 479 | + maxHeight: 700, | ||
| 480 | + maxWidth: 700, | ||
| 481 | + compressFormat: ImageCompressFormat.jpg, | ||
| 482 | + androidUiSettings: AndroidUiSettings( | ||
| 483 | + toolbarColor: Colors.white, | ||
| 484 | + toolbarTitle: "genie cropper", | ||
| 485 | + ), | ||
| 486 | + ); | ||
| 487 | + print("cropper ${val.runtimeType}"); | ||
| 488 | + capturedImageFile(val.path); | ||
| 489 | + | ||
| 490 | +} | ||
| 491 | + | ||
| 492 | +typedef capturedImageFile = String Function(String); | ||
| 493 | +typedef void OnPickImageCallback( | ||
| 494 | + double maxWidth, double maxHeight, int quality); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -52,7 +52,8 @@ dependencies: | ... | @@ -52,7 +52,8 @@ dependencies: |
| 52 | # 启动URL的插件(支持Web) https://github.com/flutter/plugins/tree/master/packages/url_launcher | 52 | # 启动URL的插件(支持Web) https://github.com/flutter/plugins/tree/master/packages/url_launcher |
| 53 | url_launcher: ^6.0.18 | 53 | url_launcher: ^6.0.18 |
| 54 | # 图片选择插件(支持Web) https://github.com/flutter/plugins/tree/master/packages/image_picker | 54 | # 图片选择插件(支持Web) https://github.com/flutter/plugins/tree/master/packages/image_picker |
| 55 | - image_picker: ^0.8.4+5 | 55 | + image_picker: ^0.8.5 |
| 56 | + image_cropper: ^2.0.0 | ||
| 56 | # 侧滑删除 https://github.com/letsar/flutter_slidable | 57 | # 侧滑删除 https://github.com/letsar/flutter_slidable |
| 57 | flutter_slidable: ^1.1.0 | 58 | flutter_slidable: ^1.1.0 |
| 58 | # WebView插件 https://github.com/flutter/plugins/tree/master/packages/webview_flutter | 59 | # WebView插件 https://github.com/flutter/plugins/tree/master/packages/webview_flutter | ... | ... |
-
Please register or login to post a comment