| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import 'dart:async';
- import 'package:fast/constants.dart';
- import 'package:fast/model/model.dart';
- import 'package:fast/utils/api.dart';
- import 'package:fast/utils/global.dart';
- import 'package:fast/utils/http_utils.dart';
- import 'package:fast/utils/size_fit.dart';
- import 'package:fast/view/component/navi_bar.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'component/fast_btn.dart';
- import 'component/toast.dart';
- class Nickname extends StatefulWidget {
- const Nickname({Key? key}) : super(key: key);
- @override
- State<Nickname> createState() => _NicknameState();
- }
- class _NicknameState extends State<Nickname> {
- late UserBean userBean;
- String name = '';
- @override
- void initState() {
- userBean = Global().userBean!;
- name = userBean.nickname!;
- super.initState();
- }
- Future update() async{
- if (name.trim().isEmpty){
- return;
- }
- var data =
- await HttpUtils.post(Api.userInfo, data: {'nickname': name});
- if (data!=null){
- showDialog(
- context: context,
- barrierDismissible: false,
- barrierColor: Colors.transparent,
- builder: (BuildContext context) {
- return Toast(
- title: '更新成功',
- content: const SizedBox(width: 0,),
- );
- });
- Timer(const Duration(seconds: 3), (){
- Get.back();
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- EdgeInsets safePadding = MediaQuery.of(context).padding;
- return Material(
- child: Container(
- padding: EdgeInsets.only(
- top: 0, bottom: safePadding.bottom),
- color: kBgColor,
- alignment: Alignment.centerLeft,
- child:
- Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
- NaviBar(
- title: '昵称',
- closeCallback: () {
- Get.back();
- }),
- Container(
- margin: EdgeInsets.fromLTRB(14.px, 30.px, 14.px, 20.px),
- padding: EdgeInsets.only(left: 18.px, right: 18.px, top: 5.px),
- height: 54.px,
- decoration: BoxDecoration(
- color: const Color(0x26C4CCDA),
- borderRadius: BorderRadius.all(Radius.circular(16.px))),
- child: TextFormField(
- initialValue: userBean.nickname,
- onChanged: (value) => {
- setState(() {
- name = value;
- })
- },
- style: TextStyle(color: Colors.white, fontSize: 16.px),
- cursorColor: Colors.white,
- autofocus: true,
- decoration: const InputDecoration(
- counterText: "",
- hintText: '请填写您的昵称,2~10个汉字',
- border: InputBorder.none,
- contentPadding: EdgeInsets.zero,
- hintStyle: TextStyle(color: Color(0x66FFFFFF))),
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: 14.px),
- child: FastBtn(
- title: "确定",
- disable: name.isEmpty,
- width: 347.px,
- height: 50.px,
- callback: () {
- update();
- }),
- )
- ])));
- }
- }
|