kidd3166 4 年之前
父节点
当前提交
8721f6a296
共有 2 个文件被更改,包括 60 次插入55 次删除
  1. 60 46
      lib/pages/login/login_widget.dart
  2. 0 9
      lib/pages/my/user_info_page.dart

+ 60 - 46
lib/pages/login/login_widget.dart

@@ -10,6 +10,7 @@ import 'package:sport/pages/login/license.dart';
 import 'package:sport/provider/user_model.dart';
 import 'package:sport/services/api/inject_api.dart';
 import 'package:sport/widgets/button_primary.dart';
+import 'package:sport/widgets/dialog/request_dialog.dart';
 
 class Input extends StatefulWidget {
   String labelText;
@@ -62,28 +63,41 @@ class _InputState extends State<Input> {
               if (widget.textInputType == TextInputType.phone) WhitelistingTextInputFormatter(RegExp("[0-9*#]")),
             ],
             decoration: InputDecoration(
-              counterText: "",
-              contentPadding: EdgeInsets.symmetric(vertical: widget.height >= 40 ? 14.0: 9.0, horizontal: 16.0),
-              border: OutlineInputBorder(
-                borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1),width: 0.5),
-                borderRadius: BorderRadius.all(Radius.circular(44.0)),
-              ),
-              focusedBorder: OutlineInputBorder(
-                borderSide: BorderSide(color: Theme.of(context).accentColor,width:1.0),
-                borderRadius: BorderRadius.all(Radius.circular(44.0)),
-              ),
-              enabledBorder: OutlineInputBorder(
-                borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1),width: 0.5),
-                borderRadius: BorderRadius.all(Radius.circular(44.0)),
-              ),
-              labelText: widget.labelText,
-              labelStyle: TextStyle(fontSize: 14.0, color: Color(0xffc2c2c2)),
-              floatingLabelBehavior: FloatingLabelBehavior.never,
-             prefixIcon:  widget.textInputType == TextInputType.phone ?Row(children: <Widget>[Padding(
-               padding: const EdgeInsets.only(left: 12.0, right: 4.0),
-               child: Text("+86", style: Theme.of(context).textTheme.subtitle1,),
-             ), VerticalDivider(indent: 8.0, endIndent: 8.0,)],mainAxisSize: MainAxisSize.min,):null
-            ),
+                counterText: "",
+                contentPadding: EdgeInsets.symmetric(vertical: widget.height >= 40 ? 14.0 : 9.0, horizontal: 16.0),
+                border: OutlineInputBorder(
+                  borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1), width: 0.5),
+                  borderRadius: BorderRadius.all(Radius.circular(44.0)),
+                ),
+                focusedBorder: OutlineInputBorder(
+                  borderSide: BorderSide(color: Theme.of(context).accentColor, width: 1.0),
+                  borderRadius: BorderRadius.all(Radius.circular(44.0)),
+                ),
+                enabledBorder: OutlineInputBorder(
+                  borderSide: BorderSide(color: Color.fromRGBO(206, 206, 206, 1), width: 0.5),
+                  borderRadius: BorderRadius.all(Radius.circular(44.0)),
+                ),
+                labelText: widget.labelText,
+                labelStyle: TextStyle(fontSize: 14.0, color: Color(0xffc2c2c2)),
+                floatingLabelBehavior: FloatingLabelBehavior.never,
+                prefixIcon: widget.textInputType == TextInputType.phone
+                    ? Row(
+                        children: <Widget>[
+                          Padding(
+                            padding: const EdgeInsets.only(left: 12.0, right: 4.0),
+                            child: Text(
+                              "+86",
+                              style: Theme.of(context).textTheme.subtitle1,
+                            ),
+                          ),
+                          VerticalDivider(
+                            indent: 8.0,
+                            endIndent: 8.0,
+                          )
+                        ],
+                        mainAxisSize: MainAxisSize.min,
+                      )
+                    : null),
             onChanged: widget.callBack));
   }
 }
@@ -137,7 +151,7 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
   @override
   void initState() {
     super.initState();
-    _openImage();
+    _openImage().then((value) => setState(() {}));
   }
 
   @override
@@ -148,12 +162,12 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
     _lastCropped?.delete();
   }
 
-  Future<void> _cropImage() async {
+  Future<String> _cropImage() async {
     final scale = cropKey.currentState.scale;
     final area = cropKey.currentState.area;
     if (area == null) {
       // cannot crop, widget is not setup
-      return;
+      return null;
     }
 
     // scale up to use maximum possible number of pixels
@@ -173,21 +187,14 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
 
     _lastCropped?.delete();
     _lastCropped = file;
-    setState(() {
-      _sample = null;
-    });
+
     print(_file);
-    fetchUploadProductBanner(_file);
-    Navigator.pop(context, _lastCropped);
+    return await fetchUploadProductBanner(_file);
   }
 
-  void fetchUploadProductBanner(File path) async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-
+  Future<String> fetchUploadProductBanner(File path) async {
     var resp = await loginApi.setAvatar(path);
-    String uploadUrl = resp.data;
-    Provider.of<UserModel>(context, listen: false).saveUserInfoAvator(uploadUrl);
-    prefs.setString('avatar', uploadUrl);
+    return resp.data;
   }
 
   Future<void> _openImage() async {
@@ -204,10 +211,8 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
     _sample?.delete();
     _file?.delete();
 
-    setState(() {
-      _sample = sample;
-      _file = file;
-    });
+    _sample = sample;
+    _file = file;
   }
 
   @override
@@ -227,12 +232,21 @@ class _BuildCroppingImagePageState extends State<BuildCroppingImagePage> with In
                   mainAxisAlignment: MainAxisAlignment.spaceAround,
                   children: <Widget>[
                     FlatButton(
-                      child: Text(
-                        '确定',
-                        style: Theme.of(context).textTheme.button.copyWith(color: Colors.white),
-                      ),
-                      onPressed: () => _cropImage(),
-                    ),
+                        child: Text(
+                          '确定',
+                          style: Theme.of(context).textTheme.button.copyWith(color: Colors.white),
+                        ),
+                        onPressed: () async {
+                          await request(context, () async {
+                            var url = await _cropImage();
+                            if (url?.isNotEmpty == true) {
+                              SharedPreferences prefs = await SharedPreferences.getInstance();
+                              prefs.setString('avatar', url);
+                              Provider.of<UserModel>(context, listen: false).saveUserInfoAvator(url);
+                              Navigator.pop(context, _file);
+                            }
+                          });
+                        }),
                   ],
                 ),
               )

+ 0 - 9
lib/pages/my/user_info_page.dart

@@ -43,15 +43,6 @@ class _PageState extends State<UserInfoPage> with InjectLoginApi {
     super.dispose();
   }
 
-  void fetchUploadProductBanner(File path) async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-
-    var resp = await loginApi.setAvatar(path);
-    String uploadUrl = resp.data;
-    prefs.setString('avatar', uploadUrl);
-    Provider.of<UserModel>(context, listen: false).saveUserInfoAvator(uploadUrl);
-  }
-
   @override
   Widget build(BuildContext context) {
     return Scaffold(