|
| 1 | +import 'package:data_plugin/bmob/table/bmob_user.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter/services.dart'; |
| 4 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 5 | +import 'package:flutter_svg/svg.dart'; |
| 6 | +import 'package:timefly/blocs/theme/theme_bloc.dart'; |
| 7 | +import 'package:timefly/blocs/theme/theme_state.dart'; |
| 8 | +import 'package:timefly/models/user.dart'; |
| 9 | +import 'package:timefly/utils/system_util.dart'; |
| 10 | +import 'package:timefly/widget/custom_edit_field.dart'; |
| 11 | + |
| 12 | +import '../app_theme.dart'; |
| 13 | + |
| 14 | +class SettingsScreen extends StatefulWidget { |
| 15 | + @override |
| 16 | + _SettingsScreenState createState() => _SettingsScreenState(); |
| 17 | +} |
| 18 | + |
| 19 | +class _SettingsScreenState extends State<SettingsScreen> { |
| 20 | + @override |
| 21 | + Widget build(BuildContext context) { |
| 22 | + return BlocBuilder<ThemeBloc, ThemeState>( |
| 23 | + builder: (context, state) { |
| 24 | + SystemUtil.changeStateBarMode( |
| 25 | + AppTheme.appTheme.isDark() ? Brightness.light : Brightness.dark); |
| 26 | + return Container( |
| 27 | + color: AppTheme.appTheme.containerBackgroundColor(), |
| 28 | + child: Stack( |
| 29 | + children: [ |
| 30 | + ListView(physics: ClampingScrollPhysics(), children: [ |
| 31 | + Container( |
| 32 | + margin: EdgeInsets.only( |
| 33 | + top: MediaQuery.of(context).padding.top, right: 24), |
| 34 | + alignment: Alignment.topRight, |
| 35 | + child: ClipRRect( |
| 36 | + borderRadius: BorderRadius.all(Radius.circular(16)), |
| 37 | + child: Image.network( |
| 38 | + 'https://c-ssl.duitang.com/uploads/item/201903/06/20190306091021_kzhxr.jpg', |
| 39 | + width: 130, |
| 40 | + height: 130, |
| 41 | + fit: BoxFit.cover, |
| 42 | + ), |
| 43 | + ), |
| 44 | + ), |
| 45 | + ChangeUserInfoView(), |
| 46 | + SizedBox( |
| 47 | + height: 100, |
| 48 | + ) |
| 49 | + ]), |
| 50 | + GestureDetector( |
| 51 | + onTap: () { |
| 52 | + Navigator.of(context).pop(); |
| 53 | + }, |
| 54 | + child: Container( |
| 55 | + alignment: Alignment.centerLeft, |
| 56 | + margin: EdgeInsets.only( |
| 57 | + top: MediaQuery.of(context).padding.top + 26), |
| 58 | + height: 45, |
| 59 | + child: Container( |
| 60 | + alignment: Alignment.center, |
| 61 | + width: 90, |
| 62 | + decoration: BoxDecoration( |
| 63 | + shape: BoxShape.rectangle, |
| 64 | + borderRadius: BorderRadius.only( |
| 65 | + topRight: Radius.circular(26), |
| 66 | + bottomRight: Radius.circular(26)), |
| 67 | + color: AppTheme.appTheme.cardBackgroundColor(), |
| 68 | + boxShadow: AppTheme.appTheme.containerBoxShadow()), |
| 69 | + child: SvgPicture.asset( |
| 70 | + 'assets/images/fanhui.svg', |
| 71 | + width: 25, |
| 72 | + height: 25, |
| 73 | + color: AppTheme.appTheme.normalColor().withOpacity(0.8), |
| 74 | + ), |
| 75 | + ), |
| 76 | + ), |
| 77 | + ) |
| 78 | + ], |
| 79 | + ), |
| 80 | + ); |
| 81 | + }, |
| 82 | + ); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +class ChangeUserInfoView extends StatefulWidget { |
| 87 | + @override |
| 88 | + State<StatefulWidget> createState() { |
| 89 | + return _ChangeUserInfoViewState(); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +class _ChangeUserInfoViewState extends State<ChangeUserInfoView> { |
| 94 | + String userName; |
| 95 | + |
| 96 | + @override |
| 97 | + void initState() { |
| 98 | + userName = SessionUtils.sharedInstance().currentUser.username; |
| 99 | + super.initState(); |
| 100 | + } |
| 101 | + |
| 102 | + @override |
| 103 | + Widget build(BuildContext context) { |
| 104 | + return Container( |
| 105 | + margin: EdgeInsets.only(top: 32, left: 22, right: 22), |
| 106 | + padding: EdgeInsets.only(top: 16, bottom: 16), |
| 107 | + decoration: BoxDecoration( |
| 108 | + shape: BoxShape.rectangle, |
| 109 | + borderRadius: BorderRadius.all(Radius.circular(15)), |
| 110 | + color: AppTheme.appTheme.cardBackgroundColor(), |
| 111 | + boxShadow: AppTheme.appTheme.containerBoxShadow()), |
| 112 | + child: Column( |
| 113 | + children: [ |
| 114 | + CustomEditField( |
| 115 | + maxLength: 10, |
| 116 | + autoFucus: false, |
| 117 | + inputType: TextInputType.name, |
| 118 | + initValue: userName, |
| 119 | + hintText: '名字', |
| 120 | + hintTextStyle: AppTheme.appTheme |
| 121 | + .hint(fontWeight: FontWeight.normal, fontSize: 16), |
| 122 | + textStyle: AppTheme.appTheme |
| 123 | + .headline1(fontWeight: FontWeight.normal, fontSize: 16), |
| 124 | + containerDecoration: BoxDecoration( |
| 125 | + shape: BoxShape.rectangle, |
| 126 | + borderRadius: BorderRadius.all(Radius.circular(15)), |
| 127 | + color: AppTheme.appTheme.containerBackgroundColor()), |
| 128 | + numDecoration: BoxDecoration( |
| 129 | + shape: BoxShape.rectangle, |
| 130 | + color: AppTheme.appTheme.cardBackgroundColor(), |
| 131 | + borderRadius: BorderRadius.all(Radius.circular(15)), |
| 132 | + boxShadow: AppTheme.appTheme.containerBoxShadow()), |
| 133 | + numTextStyle: AppTheme.appTheme |
| 134 | + .themeText(fontWeight: FontWeight.bold, fontSize: 15), |
| 135 | + onValueChanged: (value) { |
| 136 | + userName = value; |
| 137 | + }, |
| 138 | + onCompleted: () async { |
| 139 | + FocusScope.of(context).requestFocus(FocusNode()); |
| 140 | + User user = SessionUtils.sharedInstance().currentUser; |
| 141 | + BmobUser bmobUser = BmobUser(); |
| 142 | + bmobUser.objectId = user.id; |
| 143 | + bmobUser.mobilePhoneNumber = user.phone; |
| 144 | + bmobUser.mobilePhoneNumberVerified = true; |
| 145 | + bmobUser.username = userName; |
| 146 | + try { |
| 147 | + await bmobUser.update(); |
| 148 | + SessionUtils.sharedInstance().updateName(userName); |
| 149 | + } catch (e) { |
| 150 | + print(e); |
| 151 | + } |
| 152 | + }, |
| 153 | + ) |
| 154 | + ], |
| 155 | + ), |
| 156 | + ); |
| 157 | + } |
| 158 | +} |
0 commit comments