栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flutter - 单击添加新的小部件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter - 单击添加新的小部件

只需用ListView替换Row。

还对高度/宽度进行了一些更改,将其签出。

import 'package:flutter/material.dart';void main() => runApp(      new MaterialApp(        home: new ResponsavelProfilePage(),      ),    );class ResponsavelProfilePage extends StatefulWidget {  @override  _ResponsavelProfilePageState createState() =>      new _ResponsavelProfilePageState();}class _ResponsavelProfilePageState extends State<ResponsavelProfilePage> {  int _count = 1;  @override  Widget build(BuildContext context) {    List<Widget> _contatos =        new List.generate(_count, (int i) => new ContactRow());    return new Scaffold(        appBar: new AppBar(          title: new Text("NonstopIO"),        ),        body: new LayoutBuilder(builder: (context, constraint) {          final _maxHeight = constraint.biggest.height / 3;          final _biggerFont = TextStyle(fontSize: _maxHeight / 6);          return new Center( child: new Column(   mainAxisAlignment: MainAxisAlignment.center,   children: <Widget>[     new TextFormField(       decoration: new InputDecoration(         labelText: 'Nome',       ),     ),     new Container(       padding: new EdgeInsets.all(20.0),     ),     new TextFormField(       decoration: new InputDecoration(         labelText: 'Data de nascimento',       ),     ),     new Container(       padding: new EdgeInsets.all(20.0),     ),     new Container(       height: 200.0,       child: new ListView(         children: _contatos,         scrollDirection: Axis.horizontal,       ),     ),     new FlatButton(       onPressed: _addNewContactRow,       child: new Icon(Icons.add),     ),     //new ContactRow()   ], ),          );        }));  }  void _addNewContactRow() {    setState(() {      _count = _count + 1;    });  }}class ContactRow extends StatefulWidget {  @override  State<StatefulWidget> createState() => new _ContactRow();}class _ContactRow extends State<ContactRow> {  @override  Widget build(BuildContext context) {    return new Container(        width: 170.0,        padding: new EdgeInsets.all(5.0),        child: new Column(children: <Widget>[          new TextFormField( decoration: new InputDecoration(   labelText: 'Contato', ),          ),          new Text("Tipo Contato: "),          new DropdownButton( value: _currentContactType, items: _dropDownMenuItems, onChanged: changedDropDownItem,          ),          new Container( padding: new EdgeInsets.all(20.0),          ),        ]));  }  List _contactTypes = ["Phone (SMS)", "Phone (Whatsapp)", "Email"];  List<DropdownMenuItem<String>> _dropDownMenuItems;  String _currentContactType;  @override  void initState() {    _dropDownMenuItems = getDropDownMenuItems();    _currentContactType = null;    super.initState();  }  List<DropdownMenuItem<String>> getDropDownMenuItems() {    List<DropdownMenuItem<String>> items = new List();    for (String city in _contactTypes) {      items.add(new DropdownMenuItem(value: city, child: new Text(city)));    }    return items;  }  void changedDropDownItem(String selectedCity) {    setState(() {      _currentContactType = selectedCity;    });  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/413828.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号