import 'package:flutter/material.dart';
import 'package:zhongfa_apps/widget/public/PublicWidget.dart';

class FormTestRoute extends StatefulWidget {
  @override
  _FormTestRouteState createState() => new _FormTestRouteState();
}

class _FormTestRouteState extends State<FormTestRoute> {
  TextEditingController selectionController = TextEditingController();
  GlobalKey _formKey = new GlobalKey<FormState>();
  @override
  void initState() {
    super.initState();
    selectionController.text="初始值";
  }
  @override
  Widget build(BuildContext context) {
    return publicAnimatedTheme(
        subWidget: Scaffold(
      appBar: AppBar(
        title: Text("通过普通的点击事件修改TextFormField的值"),
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
        child: Form(
          key: _formKey, //设置globalKey,用于后面获取FormState
          autovalidate: true, //开启自动校验
          child: Column(
            children: <Widget>[
              TextFormField(
                controller: selectionController,
                decoration: InputDecoration(
                  labelText: "用户名",
                  hintText: "用户名或邮箱",
                  icon: Icon(Icons.person),
                ),
                // 校验用户名
                
              ),
              // 登录按钮
              InkWell(
                onTap: () {
                  selectionController.text="点击赋值";
                },
                child: Text("自定义按钮", style: TextStyle(fontSize: 40)),
              )
            ],
          ),
        ),
      ),
    ));
  }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2021-10-12
  • 2021-11-30
猜你喜欢
  • 2021-12-03
  • 2021-07-16
  • 2021-11-08
  • 2021-11-17
  • 2021-07-17
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案