【问题标题】:How can I create a list with a pop up textfield?如何创建带有弹出文本字段的列表?
【发布时间】:2020-06-20 15:57:14
【问题描述】:

我可以问点什么。

我创建了一个弹出文本字段的按钮。

但是来自文本字段的输入应该创建一个列表,然后我可以稍后将其用于图表...

here is the code

请帮忙。谢谢。

【问题讨论】:

  • 欢迎堆栈溢出。请添加更多信息以了解您的问题,并添加所有复制您的问题而不是快照的最小代码。

标签: list listview flutter dart charts


【解决方案1】:

这是一个如何实现的示例! 根据您的要求修改它!

TextEditingController tc;
  List<String> list = [];

  @override
  void initState() {
    super.initState();
    tc = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add_circle),
        onPressed: (){
          showPopup();
        }
      ),
      body:ListView.builder(
        itemCount:list.length,
      itemBuilder:(con,ind)=>
        ListTile(
        title:Text(list[ind],
                  style: TextStyle(color:Colors.black)),
        )
      )
    );
  }

  void showPopup() {
    tc.text = '';
    showDialog(
        context: context,
        builder: (con) => AlertDialog(
                title: Text('Popup Tilte'),
                content: TextField(
                    controller: tc,
                    decoration: InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: 'Field Title',
                    )),
                actions: [
                  FlatButton(
                      child: Text('Add'),
                      onPressed: () {
                        if (tc.text.trim().isNotEmpty) addToList();
                        Navigator.of(con).pop();
                      })
                ]));
  }

  void addToList() {
    setState(() {
      list.add(tc.text.trim());
    });
  }

【讨论】:

    猜你喜欢
    • 2012-04-18
    • 2020-12-23
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多