简体   繁体   中英

The username field and proceed button are not visible in flutter

I am trying to create a settings page, but username field and Proceed button is not Visible. Please help. The username field and proceed button are not visible in flutter. I am trying to create a settings page, but username field and Proceed button is not Visible. Please help. The username field and proceed button are not visible in flutter. I am trying to create a settings page, but username field and Proceed button is not Visible. Please help. The username field and proceed button are not visible in flutter.

    class CreateAccountPage extends StatefulWidget {
  @override
  _CreateAccountPageState createState() => _CreateAccountPageState();
}
class _CreateAccountPageState extends State<CreateAccountPage> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();
  final _formKey = GlobalKey<FormState>();
  String username;
  submitUsername(){
    final form = _formKey.currentState;
    if(form.validate())
    {
      form.save();
      SnackBar snackBar = SnackBar(content: Text("Welcome " + username));
      _scaffoldKey.currentState.showSnackBar(snackBar);
      Timer(Duration(seconds: 4),(){
        Navigator.pop(context, username);
      });
    }
  }
    @override
  Widget build(BuildContext parentContext) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: header(context, strTitle: "Settings", disappearedBackButton:true), //only settings is visible
      body: ListView(
        children: <Widget>[
          Container(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.only(top: 26.0),
                  child: Center(
                    child: Text("Set up user name", style: TextStyle(fontSize: 260),),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.all(17.0),
                  child: Container(
                    child: Form(
                      key: _formKey,
                      autovalidate: true,
                      child: TextFormField(
                        style: TextStyle(color: Colors.white),
                        validator: (val){
                          if(val.trim().length<5 || val.isEmpty){
                            return "user name is too short";
                          }
                          else if(val.trim().length>15){
                            return "user name is too long";
                          }
                          else{
                            return null;
                          }
                        },
                        onSaved: (val) => username = val,
                        decoration: InputDecoration(
                          enabledBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Colors.grey),
                          ),
                          focusedBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Colors.white),
                          ),
                          border: OutlineInputBorder(),
                          labelText: "Username",
                          labelStyle: TextStyle(fontSize: 16.0),
                          hintText: "must be atleast 5 character",
                          hintStyle: TextStyle(color: Colors.grey),
                        ),
                      ),
                    ),
                  ),
                ),
                GestureDetector( //not displaying
                  onTap: submitUsername,
                  child: Container(
                    height: 55.0,
                    width: 360.0,
                    decoration: BoxDecoration(
                      color: Colors.lightGreenAccent,
                      borderRadius: BorderRadius.circular(8.0),
                    ),
                    child: Text(
                      "proceed",
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 16.0,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

For the missing Username field, is it possible that it is being displayed but because you have its colour set to white you just can't see it?

...
child: TextFormField(
  style: TextStyle(color: Colors.white), // Change this, or leave it out
...

and I would use either a RaisedButton(....) or FlatButton(...) for your proceed button. Instead of the gesture detector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM