简体   繁体   中英

How to add title to Container in Flutter?

I want to add a title or image on the home page of the project, how can I do that? I need help. I want to add an image describing the application above the registration or login form.

 @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return Scaffold(
        appBar: AppBar(
        title: _title(),
    ),body: Container(
      height: double.infinity,
      width: double.infinity,
      padding: const EdgeInsets.all(10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          _entryField('email', _controllerEmail),
          Padding(padding: EdgeInsets.only(bottom: 10)),
          _entryField('password', _controllerPassword),
          Padding(padding: EdgeInsets.only(bottom: 10)),
          _submitButton(),
          _loginOrRegisterButton(),
        ],
      ),
    ),
    );
  }
}

问题

You should be able to put an Image widget in your Column, right before the email entryfield. Either an AssetImage or a NetworkImage.

Add items inside Column widget,

 @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return Scaffold(
        appBar: AppBar(
        title: _title(),
    ),body: Container(
      height: double.infinity,
      width: double.infinity,
      padding: const EdgeInsets.all(10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
         Image.asset("YourImagePath",height: 100,width:200 ,fit: BoxFit.cover,), //here
          _entryField('email', _controllerEmail),
          Padding(padding: EdgeInsets.only(bottom: 10)),
          _entryField('password', _controllerPassword),
          Padding(padding: EdgeInsets.only(bottom: 10)),
          _submitButton(),
          _loginOrRegisterButton(),
        ],
      ),
    ),
    );
  }
}

Find more about assets-and-images

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