nickname.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import 'dart:async';
  2. import 'package:fast/constants.dart';
  3. import 'package:fast/model/model.dart';
  4. import 'package:fast/utils/api.dart';
  5. import 'package:fast/utils/global.dart';
  6. import 'package:fast/utils/http_utils.dart';
  7. import 'package:fast/utils/size_fit.dart';
  8. import 'package:fast/view/component/navi_bar.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:get/get.dart';
  11. import 'component/fast_btn.dart';
  12. import 'component/toast.dart';
  13. class Nickname extends StatefulWidget {
  14. const Nickname({Key? key}) : super(key: key);
  15. @override
  16. State<Nickname> createState() => _NicknameState();
  17. }
  18. class _NicknameState extends State<Nickname> {
  19. late UserBean userBean;
  20. String name = '';
  21. @override
  22. void initState() {
  23. userBean = Global().userBean!;
  24. name = userBean.nickname!;
  25. super.initState();
  26. }
  27. Future update() async{
  28. if (name.trim().isEmpty){
  29. return;
  30. }
  31. var data =
  32. await HttpUtils.post(Api.userInfo, data: {'nickname': name});
  33. if (data!=null){
  34. showDialog(
  35. context: context,
  36. barrierDismissible: false,
  37. barrierColor: Colors.transparent,
  38. builder: (BuildContext context) {
  39. return Toast(
  40. title: '更新成功',
  41. content: const SizedBox(width: 0,),
  42. );
  43. });
  44. Timer(const Duration(seconds: 3), (){
  45. Get.back();
  46. });
  47. }
  48. }
  49. @override
  50. Widget build(BuildContext context) {
  51. SizeFit.initialize(context);
  52. EdgeInsets safePadding = MediaQuery.of(context).padding;
  53. return Material(
  54. child: Container(
  55. padding: EdgeInsets.only(
  56. top: 0, bottom: safePadding.bottom),
  57. color: kBgColor,
  58. alignment: Alignment.centerLeft,
  59. child:
  60. Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
  61. NaviBar(
  62. title: '昵称',
  63. closeCallback: () {
  64. Get.back();
  65. }),
  66. Container(
  67. margin: EdgeInsets.fromLTRB(14.px, 30.px, 14.px, 20.px),
  68. padding: EdgeInsets.only(left: 18.px, right: 18.px, top: 5.px),
  69. height: 54.px,
  70. decoration: BoxDecoration(
  71. color: const Color(0x26C4CCDA),
  72. borderRadius: BorderRadius.all(Radius.circular(16.px))),
  73. child: TextFormField(
  74. initialValue: userBean.nickname,
  75. onChanged: (value) => {
  76. setState(() {
  77. name = value;
  78. })
  79. },
  80. style: TextStyle(color: Colors.white, fontSize: 16.px),
  81. cursorColor: Colors.white,
  82. autofocus: true,
  83. decoration: const InputDecoration(
  84. counterText: "",
  85. hintText: '请填写您的昵称,2~10个汉字',
  86. border: InputBorder.none,
  87. contentPadding: EdgeInsets.zero,
  88. hintStyle: TextStyle(color: Color(0x66FFFFFF))),
  89. ),
  90. ),
  91. Container(
  92. margin: EdgeInsets.only(left: 14.px),
  93. child: FastBtn(
  94. title: "确定",
  95. disable: name.isEmpty,
  96. width: 347.px,
  97. height: 50.px,
  98. callback: () {
  99. update();
  100. }),
  101. )
  102. ])));
  103. }
  104. }