123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/widgets.dart';
- import 'package:get_it/get_it.dart';
- import 'package:sport/bean/login.dart';
- import 'package:sport/pages/login/login_widget.dart';
- import 'package:sport/pages/my/weight_page.dart';
- import 'package:sport/provider/login_info_model.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/services/api/resp.dart';
- import 'package:sport/utils/click.dart';
- import 'package:sport/widgets/button_primary.dart';
- import 'package:sport/widgets/dialog/request_dialog.dart';
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/misc.dart';
- class BasicInfoPage extends StatefulWidget {
- String username;
- BasicInfoPage({required this.username});
- @override
- State<StatefulWidget> createState() {
- return _BasicInfoPageState();
- }
- }
- class _BasicInfoPageState extends State<BasicInfoPage> with InjectLoginApi, WidgetsBindingObserver {
- int _genderController = 1; // 默认选中男
- late String _name; // 用户名
- String? _lastCropped;
- TextEditingController _textEditingController = new TextEditingController();
- late ScrollController _scrollController;
- @override
- void initState() {
- super.initState();
- _name = widget.username;
- _textEditingController.text = widget.username;
- _scrollController = ScrollController();
- WidgetsBinding.instance?.addObserver(this);
- }
- @override
- void dispose() {
- WidgetsBinding.instance?.removeObserver(this);
- super.dispose();
- _scrollController.dispose();
- _textEditingController.dispose();
- }
- @override
- void didChangeMetrics() {
- super.didChangeMetrics();
- WidgetsBinding.instance?.addPostFrameCallback((_) {
- if (MediaQuery.of(context).viewInsets.bottom > 0) {
- _scrollController.animateTo(
- _scrollController.position.maxScrollExtent, //滚动到底部
- duration: const Duration(milliseconds: 300),
- curve: Curves.easeOut,
- );
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- return Center(
- child: Scaffold(
- backgroundColor: Colors.white,
- appBar: AppBar(
- elevation: 0,
- leading: IconButton(
- icon: arrowBack(),
- onPressed: () {
- NavigatorUtil.goHomePage(context);
- },
- ),
- ),
- body: SingleChildScrollView(
- controller: _scrollController,
- child: Container(
- width: double.infinity,
- padding: EdgeInsets.only(top: 44.0),
- child: Column(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(bottom: 32.0),
- child: Text(
- "基本信息填写",
- style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1), fontSize: 25.0, fontWeight: FontWeight.w600),
- ),
- ),
- InkWell(
- child: Container(
- width: 100.0,
- height: 100.0,
- margin: EdgeInsets.only(top: 40.0),
- child: CircleAvatar(
- radius: 100,
- // borderRadius: BorderRadius.all(Radius.circular(200.0)),
- backgroundImage: userAvatarProvider(_lastCropped),
- backgroundColor: Colors.black26
- ),
- ),
- onTap: () async {
- var url = await selectImage(context);
- if (url != null)
- setState(() {
- _lastCropped = url;
- });
- },
- ),
- Container(
- padding: EdgeInsets.only(top: 32.0),
- width: 300.0,
- child: Column(
- children: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- "用户名",
- style: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 16.0),
- textAlign: TextAlign.left,
- ),
- Expanded(
- child: TextField(
- textDirection: TextDirection.rtl,
- controller: _textEditingController,
- decoration: InputDecoration(
- border: InputBorder.none, hintText: '${widget.username}', hintStyle: TextStyle(color: Colors.grey), hintMaxLines: 1),
- onChanged: (value) {
- setState(() {
- _name = value;
- });
- },
- ),
- ),
- ],
- ),
- Divider(),
- ],
- )),
- Container(
- width: 300.0,
- alignment: Alignment.center,
- padding: EdgeInsets.only(top: 12.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- "性别",
- style: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 16.0),
- ),
- Row(
- children: <Widget>[
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- // 选择男人时返回1并更新组件。
- setState(() {
- _genderController = 1;
- // widget.selectCallback(_genderController);
- });
- },
- child: Row(
- children: <Widget>[
- _genderController == 1
- ? Image.asset(
- 'lib/assets/img/pop_icon_conneted.png',
- fit: BoxFit.contain,
- height: 16.0,
- width: 16.0,
- )
- : Container(
- height: 16,
- width: 16,
- ),
- Padding(
- padding: const EdgeInsets.all(5.0),
- child: Text(
- '男',
- strutStyle: fixedLine,
- style: TextStyle(
- fontSize: 16.0,
- color: Colors.black,
- ),
- ),
- ),
- ],
- ),
- ),
- SizedBox(
- width: 32.0,
- ),
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- // 选择女人时返回2并更新组件。
- setState(() {
- _genderController = 2;
- // widget.selectCallback(_genderController);
- });
- },
- child: Row(
- children: <Widget>[
- _genderController == 2
- ? Image.asset(
- 'lib/assets/img/pop_icon_conneted.png',
- fit: BoxFit.contain,
- height: 16.0,
- width: 16.0,
- )
- : Container(
- height: 16,
- width: 16,
- ),
- Padding(
- padding: const EdgeInsets.all(5.0),
- child: Text(
- '女',
- strutStyle: fixedLine,
- style: TextStyle(
- fontSize: 16.0,
- color: Colors.black,
- ),
- ),
- ),
- ],
- ),
- ),
- ],
- )
- ],
- ),
- ),
- Container(
- width: 300,
- margin: EdgeInsets.symmetric(vertical: 25),
- child: PrimaryButton(
- content: "下一步",
- callback: throttle(() async{
- int code = await request(context, () async {
- RespData<User> data = await loginApi.updateInfo(_name, _genderController, ignore_name_card: 1);
- GetIt.I<LoginInfoModel>().saveUser(context, data.data);
- return data.code;
- });
- if(code == 0){
- NavigatorUtil.goPage(context, (context) => WeightPage());
- }
- }),
- ),
- )
- ],
- ),
- ),
- )),
- );
- }
- }
|