diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 81e79c0..b14f99b 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -65,7 +65,7 @@ class _HomePageState extends State { ); } -///底部信息栏卡片 + ///底部信息栏卡片 Widget _card( String number, String text, @@ -167,6 +167,11 @@ class _HomePageState extends State { }, child: CircleAvatar( radius: 36.w, + backgroundImage: + userProvider.userInfoModel.avatar == null + ? null + : FileImage( + userProvider.userInfoModel.avatar), backgroundColor: Colors.white, child: userProvider.isSigned ? userProvider.userInfoModel.avatar == null @@ -195,7 +200,8 @@ class _HomePageState extends State { child: Column( children: [ SizedBox(height: 18.w), - Image.asset(R.ASSETS_HOME_IC_SEARCH_PNG,width:37.w,height:37.w), + Image.asset(R.ASSETS_HOME_IC_SEARCH_PNG, + width: 37.w, height: 37.w), ], ), ), @@ -296,8 +302,8 @@ class _HomePageState extends State { children: [ _menuButton( R.ASSETS_HOME_IC_POLICE_PNG, '一键报警', HomePage()), - _menuButton( - R.ASSETS_HOME_IC_VISITORS_PNG, '访客管理', VisitorManagerPage()), + _menuButton(R.ASSETS_HOME_IC_VISITORS_PNG, '访客管理', + VisitorManagerPage()), _menuButton( R.ASSETS_HOME_IC_SERVICE_PNG, '报事报修', diff --git a/lib/ui/home/personal_draw.dart b/lib/ui/home/personal_draw.dart index b3d95a0..7d38a43 100644 --- a/lib/ui/home/personal_draw.dart +++ b/lib/ui/home/personal_draw.dart @@ -71,8 +71,15 @@ class _PersonalDrawState extends State { onPressed: () {}, child: CircleAvatar( radius: 36.w, - backgroundColor: Colors.grey, - child: userProvider.isSigned ? null : null, + backgroundImage: userProvider.userInfoModel.avatar == null + ? null + : FileImage(userProvider.userInfoModel.avatar), + backgroundColor: Colors.white, + child: userProvider.isSigned + ? userProvider.userInfoModel.avatar == null + ? Icon(Icons.person_outline) + : null + : Icon(Icons.person), ), ), SizedBox(width: 24.w), diff --git a/lib/ui/settings/user_info_page.dart b/lib/ui/settings/user_info_page.dart index fcb9e2e..d25da56 100644 --- a/lib/ui/settings/user_info_page.dart +++ b/lib/ui/settings/user_info_page.dart @@ -1,8 +1,11 @@ +import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_tile.dart'; +import 'package:aku_community_manager/ui/widgets/inner/pick_image.dart'; import 'package:flutter/material.dart'; import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:get/get.dart'; +import 'package:provider/provider.dart'; class UserInfoPage extends StatefulWidget { UserInfoPage({Key key}) : super(key: key); @@ -14,20 +17,35 @@ class UserInfoPage extends StatefulWidget { class _UserInfoPageState extends State { @override Widget build(BuildContext context) { + final userProvider = Provider.of(context); return AkuScaffold( title: '个人信息', body: ListView( padding: EdgeInsets.symmetric(vertical: 24.w), children: [ AkuTile( - onTap: () {}, + onTap: () { + akuPickImage().then((file) { + userProvider.setAvatar(file); + }); + }, title: Text('头像'), height: 168.w, - suffix: CircleAvatar(radius: 60.w), + suffix: CircleAvatar( + radius: 60.w, + backgroundColor: Colors.white, + backgroundImage: userProvider.userInfoModel.avatar == null + ? null + : FileImage(userProvider.userInfoModel.avatar), + child: userProvider.userInfoModel.avatar == null + ? Icon(Icons.person_outline) + : null, + ), ), AkuTile( onTap: () {}, title: Text('昵称'), + suffix: Text(userProvider.userInfoModel.nickName), ), AkuTile( onTap: () {}, diff --git a/lib/ui/widgets/inner/pick_image.dart b/lib/ui/widgets/inner/pick_image.dart new file mode 100644 index 0000000..c4d3047 --- /dev/null +++ b/lib/ui/widgets/inner/pick_image.dart @@ -0,0 +1,51 @@ +import 'dart:io'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:image_picker/image_picker.dart'; + +Future akuPickImage() async { + return await showCupertinoModalPopup( + context: Get.context, + builder: (context) { + return CupertinoActionSheet( + title: Text('选择图片'), + actions: [ + CupertinoActionSheetAction( + onPressed: () { + ImagePicker() + .getImage( + source: ImageSource.camera, + maxHeight: 600, + maxWidth: 600, + ) + .then((file) { + Get.back(result: File(file.path)); + }); + }, + child: Text('拍照'), + ), + CupertinoActionSheetAction( + onPressed: () { + ImagePicker() + .getImage( + source: ImageSource.gallery, + maxHeight: 600, + maxWidth: 600, + ) + .then((file) { + Get.back(result: File(file.path)); + }); + }, + child: Text('相册'), + ), + ], + cancelButton: CupertinoButton( + child: Text('取消'), + onPressed: () => Get.back(), + ), + ); + }, + ); +}