panhui 7 jaren geleden
bovenliggende
commit
fedaa3bc2d
4 gewijzigde bestanden met toevoegingen van 36 en 25 verwijderingen
  1. 10 4
      lib/main.dart
  2. 20 18
      lib/pages/home.dart
  3. 5 2
      lib/pages/loginSecond.dart
  4. 1 1
      lib/state.dart

+ 10 - 4
lib/main.dart

@@ -12,11 +12,17 @@ import 'state.dart';
 
 CountState updateState(CountState state, dynamic value){
   print(value);
- if(value.action==Actions.updateToken){
-  return CountState(state.usetoken=value);
+ if(value['action']==Actions.updateToken){
+  return CountState(state.usetoken=value['val']);
  }
- else if(value.action==Actions.updateUser){
-   return CountState(state.userInfo=value);
+ else if(value['action']==Actions.updateUser){
+   return CountState(state.userInfo=value['val']);
+ }
+ else if (value['action']==Actions.updateAll){
+   
+   state.usetoken=value['token'];
+   state.userInfo=value['user'];
+   return state;
  }
  return state;
 

+ 20 - 18
lib/pages/home.dart

@@ -65,15 +65,16 @@ class _MyHomePageState extends State<MyHomePage> {
   void initState() {
     super.initState();
     userInfo = {};
-   Future.delayed(Duration(seconds: 1),(){
-     print('开始');
-       allToken = StoreProvider.of<CountState>(context).state.usetoken;
-    getUserInfo();
-   });
+    Future.delayed(Duration(seconds: 1), () {
+      print('开始');
+      allToken = StoreProvider.of<CountState>(context).state.usetoken;
+      userInfo = StoreProvider.of<CountState>(context).state.userInfo;
+      if (!userInfo.containsKey('id')) {
+        getUserInfo();
+      }
+    });
   }
 
- 
-
   @override
   void dispose() {
     super.dispose();
@@ -322,7 +323,7 @@ class _MyHomePageState extends State<MyHomePage> {
             children: <Widget>[
               Container(
                 padding: EdgeInsets.only(
-                    left: 35,
+                    left: ScreenUtil().setWidth(15),
                     bottom: 50,
                     top: 50 + MediaQueryData.fromWindow(window).padding.top),
                 margin: EdgeInsets.only(bottom: 10),
@@ -332,25 +333,25 @@ class _MyHomePageState extends State<MyHomePage> {
                 child: Row(
                   children: <Widget>[
                     Container(
-                      margin: EdgeInsets.only(right: 8),
-                      width: 86.0,
-                      height: 86.0,
+                      margin: EdgeInsets.only(right:  ScreenUtil().setWidth(8)),
+                      width:  ScreenUtil().setWidth(86),
+                      height: ScreenUtil().setWidth(86),
                       child: CircleAvatar(
-                        backgroundImage: NetworkImage(
-                            'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2884107401,3797902000&fm=27&gp=0.jpg'),
+                        backgroundImage: NetworkImage(userInfo.containsKey('icon')?userInfo['icon']:''),
                       ),
                     ),
                     Column(
                       mainAxisAlignment: MainAxisAlignment.center,
-                      crossAxisAlignment: CrossAxisAlignment.center,
+                      crossAxisAlignment: CrossAxisAlignment.start,
                       children: <Widget>[
                         Container(
+                          width:  ScreenUtil().setWidth(175),
                           padding: EdgeInsets.only(bottom: 3),
-                          child: Text('粉条',
+                          child: Text(userInfo.containsKey('nickname')?userInfo['nickname']:'',
                               style: TextStyle(
                                   fontSize: 27,
                                   fontWeight: FontWeight.w500,
-                                  color: Colors.white)),
+                                  color: Colors.white),overflow: TextOverflow.ellipsis),
                         ),
                         Row(
                           children: <Widget>[
@@ -362,7 +363,7 @@ class _MyHomePageState extends State<MyHomePage> {
                                 width: 20,
                               ),
                             ),
-                            Text('5324',
+                            Text(userInfo.containsKey('moneyCoin')?userInfo['moneyCoin'].toString():'',
                                 style: TextStyle(
                                     fontSize: 16,
                                     fontWeight: FontWeight.w900,
@@ -521,7 +522,8 @@ class _MyHomePageState extends State<MyHomePage> {
     final res = json.decode(response.toString());
     print(res);
     if (res['success']) {
-      print(res['data']);
+      StoreProvider.of<CountState>(context)
+          .dispatch({"action": Actions.updateUser, "val": res['data']});
       setState(() {
         userInfo = res['data'];
       });

+ 5 - 2
lib/pages/loginSecond.dart

@@ -136,8 +136,11 @@ class LoginSecondState extends State<LoginSecond> {
                           Toast.hide();
                           print(res);
                           if (res['success']) {
-                            StoreProvider.of<CountState>(context)
-                                .dispatch(res['token']);
+                            StoreProvider.of<CountState>(context).dispatch({
+                              "action": Actions.updateAll,
+                              "token": res['token'],
+                              "user":res['data']
+                            });
                             Toast.show(context, '登录成功', 1500, 'success');
                             Navigator.push(
                               context,

+ 1 - 1
lib/state.dart

@@ -1,6 +1,6 @@
 import 'package:meta/meta.dart';
 
-enum Actions { updateToken,updateUser }
+enum Actions { updateToken,updateUser,updateAll}
 
 @immutable
 class CountState {