basic.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:get_it/get_it.dart';
  5. import 'package:sport/bean/login.dart';
  6. import 'package:sport/pages/login/login_widget.dart';
  7. import 'package:sport/pages/my/weight_page.dart';
  8. import 'package:sport/provider/login_info_model.dart';
  9. import 'package:sport/router/navigator_util.dart';
  10. import 'package:sport/services/api/inject_api.dart';
  11. import 'package:sport/services/api/resp.dart';
  12. import 'package:sport/utils/click.dart';
  13. import 'package:sport/widgets/button_primary.dart';
  14. import 'package:sport/widgets/dialog/request_dialog.dart';
  15. import 'package:sport/widgets/image.dart';
  16. import 'package:sport/widgets/misc.dart';
  17. class BasicInfoPage extends StatefulWidget {
  18. String username;
  19. BasicInfoPage({required this.username});
  20. @override
  21. State<StatefulWidget> createState() {
  22. return _BasicInfoPageState();
  23. }
  24. }
  25. class _BasicInfoPageState extends State<BasicInfoPage> with InjectLoginApi, WidgetsBindingObserver {
  26. int _genderController = 1; // 默认选中男
  27. late String _name; // 用户名
  28. String? _lastCropped;
  29. TextEditingController _textEditingController = new TextEditingController();
  30. late ScrollController _scrollController;
  31. @override
  32. void initState() {
  33. super.initState();
  34. _name = widget.username;
  35. _textEditingController.text = widget.username;
  36. _scrollController = ScrollController();
  37. WidgetsBinding.instance?.addObserver(this);
  38. }
  39. @override
  40. void dispose() {
  41. WidgetsBinding.instance?.removeObserver(this);
  42. super.dispose();
  43. _scrollController.dispose();
  44. _textEditingController.dispose();
  45. }
  46. @override
  47. void didChangeMetrics() {
  48. super.didChangeMetrics();
  49. WidgetsBinding.instance?.addPostFrameCallback((_) {
  50. if (MediaQuery.of(context).viewInsets.bottom > 0) {
  51. _scrollController.animateTo(
  52. _scrollController.position.maxScrollExtent, //滚动到底部
  53. duration: const Duration(milliseconds: 300),
  54. curve: Curves.easeOut,
  55. );
  56. }
  57. });
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. return Center(
  62. child: Scaffold(
  63. backgroundColor: Colors.white,
  64. appBar: AppBar(
  65. elevation: 0,
  66. leading: IconButton(
  67. icon: arrowBack(),
  68. onPressed: () {
  69. NavigatorUtil.goHomePage(context);
  70. },
  71. ),
  72. ),
  73. body: SingleChildScrollView(
  74. controller: _scrollController,
  75. child: Container(
  76. width: double.infinity,
  77. padding: EdgeInsets.only(top: 44.0),
  78. child: Column(
  79. children: <Widget>[
  80. Padding(
  81. padding: EdgeInsets.only(bottom: 32.0),
  82. child: Text(
  83. "基本信息填写",
  84. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1), fontSize: 25.0, fontWeight: FontWeight.w600),
  85. ),
  86. ),
  87. InkWell(
  88. child: Container(
  89. width: 100.0,
  90. height: 100.0,
  91. margin: EdgeInsets.only(top: 40.0),
  92. child: CircleAvatar(
  93. radius: 100,
  94. // borderRadius: BorderRadius.all(Radius.circular(200.0)),
  95. backgroundImage: userAvatarProvider(_lastCropped),
  96. backgroundColor: Colors.black26
  97. ),
  98. ),
  99. onTap: () async {
  100. var url = await selectImage(context);
  101. if (url != null)
  102. setState(() {
  103. _lastCropped = url;
  104. });
  105. },
  106. ),
  107. Container(
  108. padding: EdgeInsets.only(top: 32.0),
  109. width: 300.0,
  110. child: Column(
  111. children: <Widget>[
  112. Row(
  113. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  114. children: <Widget>[
  115. Text(
  116. "用户名",
  117. style: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 16.0),
  118. textAlign: TextAlign.left,
  119. ),
  120. Expanded(
  121. child: TextField(
  122. textDirection: TextDirection.rtl,
  123. controller: _textEditingController,
  124. decoration: InputDecoration(
  125. border: InputBorder.none, hintText: '${widget.username}', hintStyle: TextStyle(color: Colors.grey), hintMaxLines: 1),
  126. onChanged: (value) {
  127. setState(() {
  128. _name = value;
  129. });
  130. },
  131. ),
  132. ),
  133. ],
  134. ),
  135. Divider(),
  136. ],
  137. )),
  138. Container(
  139. width: 300.0,
  140. alignment: Alignment.center,
  141. padding: EdgeInsets.only(top: 12.0),
  142. child: Row(
  143. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  144. children: <Widget>[
  145. Text(
  146. "性别",
  147. style: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 16.0),
  148. ),
  149. Row(
  150. children: <Widget>[
  151. GestureDetector(
  152. behavior: HitTestBehavior.opaque,
  153. onTap: () {
  154. // 选择男人时返回1并更新组件。
  155. setState(() {
  156. _genderController = 1;
  157. // widget.selectCallback(_genderController);
  158. });
  159. },
  160. child: Row(
  161. children: <Widget>[
  162. _genderController == 1
  163. ? Image.asset(
  164. 'lib/assets/img/pop_icon_conneted.png',
  165. fit: BoxFit.contain,
  166. height: 16.0,
  167. width: 16.0,
  168. )
  169. : Container(
  170. height: 16,
  171. width: 16,
  172. ),
  173. Padding(
  174. padding: const EdgeInsets.all(5.0),
  175. child: Text(
  176. '男',
  177. strutStyle: fixedLine,
  178. style: TextStyle(
  179. fontSize: 16.0,
  180. color: Colors.black,
  181. ),
  182. ),
  183. ),
  184. ],
  185. ),
  186. ),
  187. SizedBox(
  188. width: 32.0,
  189. ),
  190. GestureDetector(
  191. behavior: HitTestBehavior.opaque,
  192. onTap: () {
  193. // 选择女人时返回2并更新组件。
  194. setState(() {
  195. _genderController = 2;
  196. // widget.selectCallback(_genderController);
  197. });
  198. },
  199. child: Row(
  200. children: <Widget>[
  201. _genderController == 2
  202. ? Image.asset(
  203. 'lib/assets/img/pop_icon_conneted.png',
  204. fit: BoxFit.contain,
  205. height: 16.0,
  206. width: 16.0,
  207. )
  208. : Container(
  209. height: 16,
  210. width: 16,
  211. ),
  212. Padding(
  213. padding: const EdgeInsets.all(5.0),
  214. child: Text(
  215. '女',
  216. strutStyle: fixedLine,
  217. style: TextStyle(
  218. fontSize: 16.0,
  219. color: Colors.black,
  220. ),
  221. ),
  222. ),
  223. ],
  224. ),
  225. ),
  226. ],
  227. )
  228. ],
  229. ),
  230. ),
  231. Container(
  232. width: 300,
  233. margin: EdgeInsets.symmetric(vertical: 25),
  234. child: PrimaryButton(
  235. content: "下一步",
  236. callback: throttle(() async{
  237. int code = await request(context, () async {
  238. RespData<User> data = await loginApi.updateInfo(_name, _genderController, ignore_name_card: 1);
  239. GetIt.I<LoginInfoModel>().saveUser(context, data.data);
  240. return data.code;
  241. });
  242. if(code == 0){
  243. NavigatorUtil.goPage(context, (context) => WeightPage());
  244. }
  245. }),
  246. ),
  247. )
  248. ],
  249. ),
  250. ),
  251. )),
  252. );
  253. }
  254. }