Showing
2 changed files
with
91 additions
and
10 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( |
| 70 | - backgroundColor: Colors.red, | 73 | + child: CircleAvatar( |
| 71 | - radius: 25.px, | 74 | + backgroundColor: Colors.red, |
| 72 | - child: const Icon( | 75 | + radius: 25.px, |
| 73 | - Icons.camera_alt, | 76 | + child: const Icon( |
| 74 | - color: Colors.white, | 77 | + Icons.camera_alt, |
| 78 | + color: Colors.white, | ||
| 79 | + ), | ||
| 75 | ), | 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 | )), |
| ... | @@ -154,7 +204,7 @@ class MapScreenState extends State<AccountEditPage> | ... | @@ -154,7 +204,7 @@ class MapScreenState extends State<AccountEditPage> |
| 154 | children: <Widget>[ | 204 | children: <Widget>[ |
| 155 | Flexible( | 205 | Flexible( |
| 156 | child: TextField( | 206 | child: TextField( |
| 157 | - decoration: InputDecoration( | 207 | + decoration: InputDecoration( |
| 158 | hintText: ParlandoLocalizations.of( | 208 | hintText: ParlandoLocalizations.of( |
| 159 | context) | 209 | context) |
| 160 | .accountEditPageUserNamePlaceholder, | 210 | .accountEditPageUserNamePlaceholder, |
| ... | @@ -200,7 +250,7 @@ class MapScreenState extends State<AccountEditPage> | ... | @@ -200,7 +250,7 @@ class MapScreenState extends State<AccountEditPage> |
| 200 | children: <Widget>[ | 250 | children: <Widget>[ |
| 201 | Flexible( | 251 | Flexible( |
| 202 | child: TextField( | 252 | child: TextField( |
| 203 | - decoration: InputDecoration( | 253 | + decoration: InputDecoration( |
| 204 | hintText: ParlandoLocalizations.of( | 254 | hintText: ParlandoLocalizations.of( |
| 205 | context) | 255 | context) |
| 206 | .accountEditPageUserEmailPlaceholder, | 256 | .accountEditPageUserEmailPlaceholder, |
| ... | @@ -245,7 +295,7 @@ class MapScreenState extends State<AccountEditPage> | ... | @@ -245,7 +295,7 @@ class MapScreenState extends State<AccountEditPage> |
| 245 | children: <Widget>[ | 295 | children: <Widget>[ |
| 246 | Flexible( | 296 | Flexible( |
| 247 | child: TextField( | 297 | child: TextField( |
| 248 | - decoration: InputDecoration( | 298 | + decoration: InputDecoration( |
| 249 | hintText: ParlandoLocalizations.of( | 299 | hintText: ParlandoLocalizations.of( |
| 250 | context) | 300 | context) |
| 251 | .accountEditPageUserPhonePlaceholder, | 301 | .accountEditPageUserPhonePlaceholder, |
| ... | @@ -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