From da7ad00ccca6d665a3ef972a378b93dc27550d20 Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Fri, 30 Oct 2020 17:49:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=99=BB=E5=BD=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=AE=A1=E7=90=86=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 14 +++- lib/provider/user_provider.dart | 10 +++ lib/ui/home/home_page.dart | 12 +++- lib/ui/home/personal_draw.dart | 116 ++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 lib/provider/user_provider.dart create mode 100644 lib/ui/home/personal_draw.dart diff --git a/lib/main.dart b/lib/main.dart index 30c4223..f344cf6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,8 @@ +import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/ui/home/home_page.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:provider/provider.dart'; void main() { runApp(MyApp()); @@ -10,9 +12,15 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { - return GetMaterialApp( - title: '小蜜蜂管家', - home: HomePage(), + return MultiProvider( + providers:[ + ChangeNotifierProvider(create: (context)=>UserProvider()), + ], + child: GetMaterialApp( + title: '小蜜蜂管家', + home: HomePage(), + + ), ); } } diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart new file mode 100644 index 0000000..110c511 --- /dev/null +++ b/lib/provider/user_provider.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; +//登录状态管理 +class UserProvider extends ChangeNotifier{ + bool _isSigned=false; + get isSigned=>_isSigned; + setisSigned (bool state){ + _isSigned=state; + notifyListeners(); + } +} \ No newline at end of file diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index eb8f0f9..87ef3ec 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -1,10 +1,13 @@ +import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/tools/widget_tool.dart'; +import 'package:aku_community_manager/ui/home/personal_draw.dart'; import 'package:aku_ui/aku_ui.dart'; import 'package:aku_ui/common_widgets/aku_material_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:provider/provider.dart'; class HomePage extends StatefulWidget { HomePage({Key key}) : super(key: key); @@ -76,10 +79,11 @@ Widget _card(String number, String text, Color color) { class _HomePageState extends State { @override Widget build(BuildContext context) { + final userProvider=Provider.of(context); ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: true); return Scaffold( - drawer: Drawer(), + drawer: PersonalDraw(), backgroundColor: Color(0xFFF9F9F9), //自定义bar appBar: PreferredSize( @@ -115,11 +119,13 @@ class _HomePageState extends State { //头像按钮 child: Builder(builder: (BuildContext context) { return AkuRoundButton( - height: 36.w, + height: 72.w, onPressed: () { Scaffold.of(context).openDrawer(); }, - child: CircleAvatar(radius: 36.w), + child: CircleAvatar(radius: 36.w, + backgroundColor: Colors.grey, + child: userProvider.isSigned?null:null,), ); })), SizedBox(width: 16.w), diff --git a/lib/ui/home/personal_draw.dart b/lib/ui/home/personal_draw.dart new file mode 100644 index 0000000..5635a57 --- /dev/null +++ b/lib/ui/home/personal_draw.dart @@ -0,0 +1,116 @@ +import 'package:aku_community_manager/provider/user_provider.dart'; +import 'package:aku_community_manager/style/app_style.dart'; +import 'package:aku_ui/common_widgets/aku_button.dart'; +import 'package:aku_ui/common_widgets/aku_round_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:provider/provider.dart'; + +class PersonalDraw extends StatefulWidget { + PersonalDraw({Key key}) : super(key: key); + + @override + _PersonalDrawState createState() => _PersonalDrawState(); +} + +class _PersonalDrawState extends State { + Widget _myListTile(IconData iconData, String text) { + return AkuButton( + onPressed: () {}, + child: Container( + width: double.infinity, + height: 96.w, + padding: EdgeInsets.only(left: 32.w, top: 28.w, bottom: 28.w), + child: Row(children: [ + Icon( + iconData, + size: 40.w, + ), + SizedBox(width: 16.w), + Text( + text, + style: TextStyle( + color: AppStyle.primaryTextColor, + fontSize: 28.sp, + ), + ), + ]), + ), + ); + } + + @override + Widget build(BuildContext context) { + final userProvider = Provider.of(context); + return Drawer( + child: ListView( + children: [ + SizedBox( + height: 80.w - 40.w + ScreenUtil().statusBarHeight, + ), + //leading + Container( + margin: EdgeInsets.only(bottom: 80.w), + width: double.infinity, + height: 72.w, + child: Row( + children: [ + SizedBox(width: 32.w), + //头像按钮 + AkuRoundButton( + height: 72.w, + onPressed: () {}, + child: CircleAvatar( + radius: 36.w, + backgroundColor: Colors.grey, + child: userProvider.isSigned ? null : null, + ), + ), + SizedBox(width: 24.w), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + //登录按钮 + InkWell( + onTap: () {}, + child: userProvider.isSigned + ? Text( + '李大海', + style: TextStyle( + color: AppStyle.primaryTextColor, + fontSize: 28.sp, + fontWeight: FontWeight.bold), + ) + : Text('登录', + style: TextStyle( + color: AppStyle.primaryTextColor, + fontSize: 28.sp, + fontWeight: FontWeight.bold)), + ), + InkWell( + onTap: () {}, + child: Row( + children: [ + Icon(Icons.location_on_outlined, size: 33.w), + Text( + '深圳华悦茂峰', + style: TextStyle( + color: AppStyle.primaryTextColor, + fontSize: 24.sp), + ), + ], + ), + ), + ], + ), + ], + ), + ), + _myListTile(Icons.contact_page, '个人信息'), + _myListTile(Icons.supervised_user_circle, '联系客服'), + _myListTile(Icons.settings, '设置'), + ], + ), + ); + } +}