如何在flutter中使用字符串添加动态按钮

时间:2019-07-18 12:12:27

标签: flutter

List list=["A","B","C","D"];

我想将每个字符添加到单独的凸起按钮上。 如何仅生成4个凸起的按钮,并将这些值添加到该按钮上。喜欢,

mButton1="A";
.
.
.
mButtonN="n";

2 个答案:

答案 0 :(得分:1)

您可以使用"2019-07-18T11:29:13.623245Z" 运算符

  {
    "caption": "Execution time",
    "name": "ExecutionTime",
    "visible": true,
    "enabled": true,
    "path": "executionTime",
    "description": "Execution time",
    "dataType": "DateTime",
    "writable": true,
    "required": true,
    "number: "0000-00000-00000",
    "controlName": "DateTimePicker",
    "defaultValue": "2019-07-18T11:29:13.623245Z",
    "aspects": []
  },

答案 1 :(得分:1)

main.dart 完整代码

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> list = ["A", "B", "C", "D"];
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Stack Overflow"),
        ),
        body: Center(
          child: Column(
            children: list.map((String data) {
              return RaisedButton(
                child: Text(data),
                onPressed: () {
                  print(data);
                },
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}