From 4f167c2fd74efeddcfd9ce38a643603cc8f2e684 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Wed, 20 Jan 2021 18:49:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=89=E6=8B=A9=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E5=BC=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/personal/user_profile_page.dart | 35 +++++++++++++++++++---- pubspec.lock | 21 ++++++++++++++ pubspec.yaml | 2 ++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/pages/personal/user_profile_page.dart b/lib/pages/personal/user_profile_page.dart index 06396197..c168f3e0 100644 --- a/lib/pages/personal/user_profile_page.dart +++ b/lib/pages/personal/user_profile_page.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/pages/personal/change_nick_name_page.dart'; import 'package:akuCommunity/pages/personal/update_tel_page.dart'; @@ -8,6 +10,7 @@ import 'package:common_utils/common_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:image_picker/image_picker.dart'; import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; @@ -52,6 +55,32 @@ class _UserProfilePageState extends State { ); } + _pickAvatar() async { + PickedFile file = await Get.bottomSheet(CupertinoActionSheet( + title: '选择头像'.text.isIntrinsic.make(), + actions: [ + CupertinoDialogAction( + onPressed: () async => Get.back( + result: await ImagePicker().getImage(source: ImageSource.gallery), + ), + child: '相册'.text.isIntrinsic.make(), + ), + CupertinoDialogAction( + onPressed: () async => Get.back( + result: await ImagePicker().getImage(source: ImageSource.camera), + ), + child: '相机'.text.isIntrinsic.make(), + ), + ], + cancelButton: CupertinoDialogAction( + onPressed: Get.back, + child: '取消'.text.isIntrinsic.make(), + ), + )); + if (file == null) return; + //TODO upload avatar. + } + @override Widget build(BuildContext context) { final userProvider = Provider.of(context); @@ -59,11 +88,7 @@ class _UserProfilePageState extends State { title: '个人资料', body: ListView( children: [ - _buildTile( - '头像', - CircleAvatar(), - onPressed: () {}, - ), + _buildTile('头像', CircleAvatar(), onPressed: _pickAvatar), _buildTile( '姓名', userProvider.userInfoModel.name.text.make(), diff --git a/pubspec.lock b/pubspec.lock index 1ebc203a..fb6026d8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -389,6 +389,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.5" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.11" flutter_redux: dependency: "direct main" description: @@ -518,6 +525,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.14" + image_picker: + dependency: "direct main" + description: + name: image_picker + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.6.7+21" + image_picker_platform_interface: + dependency: transitive + description: + name: image_picker_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.1" image_stack: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 92054b7f..41269525 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -98,6 +98,8 @@ dependencies: git: url: http://192.168.2.201:8099/zhangmeng/random_character.git + image_picker: ^0.6.7+21 + dev_dependencies: flutter_test: sdk: flutter