添加选择头像

hmxc
小赖 4 years ago
parent accc292932
commit a6def9e502

@ -167,6 +167,11 @@ class _HomePageState extends State<HomePage> {
}, },
child: CircleAvatar( child: CircleAvatar(
radius: 36.w, radius: 36.w,
backgroundImage:
userProvider.userInfoModel.avatar == null
? null
: FileImage(
userProvider.userInfoModel.avatar),
backgroundColor: Colors.white, backgroundColor: Colors.white,
child: userProvider.isSigned child: userProvider.isSigned
? userProvider.userInfoModel.avatar == null ? userProvider.userInfoModel.avatar == null
@ -195,7 +200,8 @@ class _HomePageState extends State<HomePage> {
child: Column( child: Column(
children: [ children: [
SizedBox(height: 18.w), 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<HomePage> {
children: [ children: [
_menuButton( _menuButton(
R.ASSETS_HOME_IC_POLICE_PNG, '一键报警', HomePage()), R.ASSETS_HOME_IC_POLICE_PNG, '一键报警', HomePage()),
_menuButton( _menuButton(R.ASSETS_HOME_IC_VISITORS_PNG, '访客管理',
R.ASSETS_HOME_IC_VISITORS_PNG, '访客管理', VisitorManagerPage()), VisitorManagerPage()),
_menuButton( _menuButton(
R.ASSETS_HOME_IC_SERVICE_PNG, R.ASSETS_HOME_IC_SERVICE_PNG,
'报事报修', '报事报修',

@ -71,8 +71,15 @@ class _PersonalDrawState extends State<PersonalDraw> {
onPressed: () {}, onPressed: () {},
child: CircleAvatar( child: CircleAvatar(
radius: 36.w, radius: 36.w,
backgroundColor: Colors.grey, backgroundImage: userProvider.userInfoModel.avatar == null
child: userProvider.isSigned ? null : 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), SizedBox(width: 24.w),

@ -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_scaffold.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_tile.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:flutter/material.dart';
import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:aku_community_manager/tools/screen_tool.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart';
class UserInfoPage extends StatefulWidget { class UserInfoPage extends StatefulWidget {
UserInfoPage({Key key}) : super(key: key); UserInfoPage({Key key}) : super(key: key);
@ -14,20 +17,35 @@ class UserInfoPage extends StatefulWidget {
class _UserInfoPageState extends State<UserInfoPage> { class _UserInfoPageState extends State<UserInfoPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final userProvider = Provider.of<UserProvider>(context);
return AkuScaffold( return AkuScaffold(
title: '个人信息', title: '个人信息',
body: ListView( body: ListView(
padding: EdgeInsets.symmetric(vertical: 24.w), padding: EdgeInsets.symmetric(vertical: 24.w),
children: [ children: [
AkuTile( AkuTile(
onTap: () {}, onTap: () {
akuPickImage().then((file) {
userProvider.setAvatar(file);
});
},
title: Text('头像'), title: Text('头像'),
height: 168.w, 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( AkuTile(
onTap: () {}, onTap: () {},
title: Text('昵称'), title: Text('昵称'),
suffix: Text(userProvider.userInfoModel.nickName),
), ),
AkuTile( AkuTile(
onTap: () {}, onTap: () {},

@ -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<File> 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(),
),
);
},
);
}
Loading…
Cancel
Save