添加登录信息状态管理

hmxc
张萌 4 years ago
parent 8777517b13
commit 83ede8be8f

@ -1,4 +1,5 @@
import 'package:akuCommunity/pages/tab_navigator.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:ani_route/ani_route.dart';
import 'package:flutter/material.dart';
@ -39,6 +40,7 @@ class _MyAppState extends State<MyApp> {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => CartProvidde()),
ChangeNotifierProvider(create: (context)=>UserProvider()),
],
child: OKToast(
textStyle: TextStyle(fontSize: 19.0, color: Colors.white),

@ -1,4 +1,5 @@
import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:ani_route/ani_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
@ -11,6 +12,7 @@ import 'package:akuCommunity/widget/single_ad_space.dart';
import 'package:akuCommunity/widget/cached_image_wrapper.dart';
import 'package:akuCommunity/routers/page_routers.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
class PersonalIndex extends StatefulWidget {
final bool isSign;
@ -33,6 +35,7 @@ class _PersonalIndexState extends State<PersonalIndex>
}
SliverAppBar _sliverAppBar(double height) {
final userProvider=Provider.of<UserProvider>(context);
return SliverAppBar(
pinned: true,
elevation: 0,
@ -71,18 +74,18 @@ class _PersonalIndexState extends State<PersonalIndex>
'https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1851283359,3457678391&fm=26&gp=0.jpg',
width: Screenutil.length(106),
height: Screenutil.length(106),
isSigned: _isSigned,
isSigned: userProvider.isSigned,
),
),
),
InkWell(
onTap: (){
_isSigned? null:ARoute.push(context, SignInPage());
userProvider.isSigned? null:ARoute.push(context, SignInPage());
},
child: Container(
margin: EdgeInsets.only(
left: Screenutil.length(16)),
child: _isSigned
child: userProvider.isSigned
? Text(
'Cheailune',
style: TextStyle(

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:akuCommunity/pages/setting_page/agreement_page/agreement_page.dart';
import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:ani_route/ani_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
@ -10,6 +11,8 @@ import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/widget/common_app_bar.dart';
import 'package:akuCommunity/routers/page_routers.dart';
import 'package:akuCommunity/widget/custom_action_sheet.dart';
import 'package:provider/provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'agreement_page/privacy_page.dart';
@ -50,7 +53,7 @@ class _SettingPageState extends State<SettingPage> {
'isSwitch': false,
},
{
'title':'隐私政策',
'title': '隐私政策',
'isSwitch': false,
}
];
@ -176,10 +179,10 @@ class _SettingPageState extends State<SettingPage> {
);
break;
case '用户协议':
ARoute.push(context, AgreementPage());
ARoute.push(context, AgreementPage());
break;
case '隐私政策':
ARoute.push(context,PrivacyPage());
case '隐私政策':
ARoute.push(context, PrivacyPage());
break;
default:
}
@ -233,8 +236,10 @@ class _SettingPageState extends State<SettingPage> {
}
Widget _containerQuit() {
final userProvider = Provider.of<UserProvider>(context);
return InkWell(
onTap: () {
userProvider.isSigned?
showCupertinoModalPopup(
context: context,
builder: (context) {
@ -249,6 +254,8 @@ class _SettingPageState extends State<SettingPage> {
),
),
onPressed: () {
userProvider.setisSigned(false);
ARoute.pop(context);
// Navigator.popUntil(context, (route) {
// return !Navigator.canPop(context);
// });
@ -257,7 +264,6 @@ class _SettingPageState extends State<SettingPage> {
// CupertinoPageRoute(
// builder: (context) => SignInPage(),
// ));
ARoute.push(context, SignInPage());
},
),
],
@ -269,25 +275,46 @@ class _SettingPageState extends State<SettingPage> {
),
);
},
);
):ARoute.push(context, SignInPage());
},
child: Container(
color: Colors.white,
height: Screenutil.length(96),
padding: EdgeInsets.only(
top: Screenutil.length(26),
bottom: Screenutil.length(25),
),
alignment: Alignment.center,
child: Text(
'退出当前帐号',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: BaseStyle.fontSize32,
color: BaseStyle.color333333,
),
),
),
child: userProvider.isSigned
? Container(
color: Colors.white,
height: Screenutil.length(96),
padding: EdgeInsets.only(
top: Screenutil.length(26),
bottom: Screenutil.length(25),
),
alignment: Alignment.center,
child: Text(
'退出当前帐号',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: BaseStyle.fontSize32,
color: BaseStyle.color333333,
),
),
)
: Container(
alignment: Alignment.center,
height: Screenutil.length(89),
width: Screenutil.length(586),
padding: EdgeInsets.only(
top: Screenutil.length(25), bottom: Screenutil.length(24)),
margin: EdgeInsets.symmetric(horizontal: Screenutil.length(82)),
decoration: BoxDecoration(
color: Color(0xffffc40c),
borderRadius: BorderRadius.all(Radius.circular(36)),
),
child: Text(
'登录',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: BaseStyle.fontSize28,
color: BaseStyle.color333333,
),
),
),
);
}

@ -1,10 +1,12 @@
import 'package:akuCommunity/pages/tab_navigator.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:ani_route/ani_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:akuCommunity/utils/screenutil.dart';
import 'package:akuCommunity/base/base_style.dart';
import 'package:provider/provider.dart';
class UserAuthenticationPage extends StatefulWidget {
final BuildContext context;
@ -26,6 +28,7 @@ class _UserAuthenticationPageState extends State<UserAuthenticationPage> {
];
AppBar _appBar() {
final userProvider=Provider.of<UserProvider>(context);
return AppBar(
elevation: 0,
backgroundColor: Colors.white,
@ -39,8 +42,9 @@ class _UserAuthenticationPageState extends State<UserAuthenticationPage> {
MaterialButton(
child: Text('跳过'),
onPressed: () {
userProvider.setisSigned(true);
ARoute.pop(context,root: true);
ARoute.pushReplace(context, TabNavigator(isSign: true,));
ARoute.pushReplace(context, TabNavigator());
},
),
],

@ -11,9 +11,7 @@ import 'personal/personal_page.dart';
class TabNavigator extends StatefulWidget {
final bool isSign;
const TabNavigator({Key key, this.isSign=false}) : super(key: key);
const TabNavigator({Key key, }) : super(key: key);
@override
_TabNavigatorState createState() => _TabNavigatorState();
}
@ -37,7 +35,6 @@ _pages=[
PropertyIndex(),
CommunityIndex(),
PersonalIndex(
isSign: widget.isSign,
)
];
}

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