Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在颤振中使用下拉选择创建窗体模态_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 如何在颤振中使用下拉选择创建窗体模态

Flutter 如何在颤振中使用下拉选择创建窗体模态,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我是一个新手,这是我第一次申请。我一直在尝试创建一个表单模式,下拉选择将从服务器接收其数据。但现在我正在使用我创建的数组中的值,但在我选择一个项目后,它并没有设置值。我试图添加setState(),但显示错误。有人能帮我吗 这是我的密码 import 'dart:async'; import 'package:flutter/material.dart'; import 'package:erg_app/ProfilePage.dart'; void main() => runApp(

我是一个新手,这是我第一次申请。我一直在尝试创建一个表单模式,下拉选择将从服务器接收其数据。但现在我正在使用我创建的数组中的值,但在我选择一个项目后,它并没有设置值。我试图添加setState(),但显示错误。有人能帮我吗

这是我的密码

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:erg_app/ProfilePage.dart';

void main() => runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: StockPage(),
    )
);

class StockPage extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Inventory Data',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      home: StockInventory(),
    );
  }
}

class StockInventory extends StatefulWidget {

  StockInventory({Key key}) : super(key: key); //Find out meaning

  @override
  _StockInventoryState createState() => _StockInventoryState();
}


class _StockInventoryState extends State<StockInventory> {


   List<Products> products;
  List<Products> selectedProducts;
  bool sort;

  @override
  void initState() {
    sort = false;
    selectedProducts = [];
    products = Products.getProducts();
    super.initState();
  }

  onSortColum(int columnIndex, bool ascending) {
    if (columnIndex == 0) {
      if (ascending) {
        products.sort((a, b) => a.name.compareTo(b.name));
      } else {
        products.sort((a, b) => b.name.compareTo(a.name));
      }
    }
  }

   @override
  Widget build(BuildContext context){
        return Scaffold(
          appBar: AppBar(
          title: new Center(child: new Text('Daily Stock Taking', textAlign: TextAlign.center)),
          automaticallyImplyLeading: false,
          iconTheme: IconThemeData(color: Colors.white),
          backgroundColor: Colors.green,),

          body: Container(
            child: ListView(
              children: <Widget>[
                Container(
                  margin: const EdgeInsets.only(right: 20, top: 20),
                  child: Align(
                     alignment: Alignment.bottomRight,
                     child: RaisedButton(
                        padding: EdgeInsets.fromLTRB(14, 10, 14, 10),
                        color: Colors.green,
                        child: Text("Take Inventory", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14), ),
                        onPressed: () {
                          // Navigator.of(context).push(MaterialPageRoute(builder: (context) => ProfilePage()));
                          showSimpleCustomDialog(context);
                        },
                        shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(50),

                      ),
                      ),
                    ),
                  ),

                Container(
                    padding: EdgeInsets.only(top: 30, bottom: 30),
                    child: DataTable(
                    sortAscending: sort,
                    sortColumnIndex: 0,
                    columns: [
                      DataColumn(
                        label: Text("S/No", style: TextStyle(fontSize: 16)),
                        numeric: false,
                      ),
                      DataColumn(
                          label: Text("Item", style: TextStyle(fontSize: 16)),
                          numeric: false,
                          onSort: (columnIndex, ascending) {
                            setState(() {
                              sort = !sort;
                            });
                            onSortColum(columnIndex, ascending);
                          }),
                      DataColumn(
                        label: Text("QtyInStock", style: TextStyle(fontSize: 16)),
                        numeric: false,
                      ),
                      DataColumn(
                        label: Text("Unit", style: TextStyle(fontSize: 16)),
                        numeric: false,
                      ),
                    ],
                    rows: products
                        .map(
                          (product) => DataRow(
                              selected: selectedProducts.contains(product),
                              cells: [
                                DataCell(
                                  Text(product.count),
                                  onTap: () {
                                    print('Selected ${product.count}');
                                  },
                                ),
                                DataCell(
                                  Text(product.name),
                                  onTap: () {
                                    print('Selected ${product.name}');
                                  },
                                ),
                                DataCell(
                                  Text(product.itemqty),
                                  onTap: () {
                                    print('Selected ${product.itemqty}');
                                  },
                                ),
                                DataCell(
                                  Text(product.itemqty),
                                  onTap: () {
                                    print('Selected ${product.itemqty}');
                                  },
                                ),
                              ]),
                        ).toList(),
                    ),          
                ),
                Container(
                    child: Center(
                      child: RaisedButton(
                        padding: EdgeInsets.fromLTRB(80, 10, 80, 10),
                        color: Colors.green,
                        child: Text("Post Inventory", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14), ),
                        onPressed: () {
                          Navigator.of(context).push(MaterialPageRoute(builder: (context) => ProfilePage()));
                        },
                        shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(50),
                      ),
                      ),
                    ),
                  ),
              ],
            ),
          ),
        );
  }
}



class Products {
  String count;
  String name;
  String measuringunit;
  String itemqty;
  Products({this.count, this.name, this.itemqty, this.measuringunit});

  static List<Products> getProducts() {
    return <Products>[
      Products(count:"1", name: "NPK Fertilizer", itemqty: "50", measuringunit: "bag",),
      Products(count:"2", name: "Urea Fertilizer", itemqty: "560", measuringunit: "bag",),
      Products(count:"3", name: "Spray", itemqty: "150", measuringunit: "bottles",),
    ];
  }


}


void showSimpleCustomDialog(BuildContext context) {
  String dropdownValue = 'SelectItem';

  // TextEditingController _controller = TextEditingController(text: dropdownValue);

    Dialog simpleDialog = Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Container(
        height: 300.0,
        width: 300.0,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
           Padding( 
                padding: EdgeInsets.only(top:20, bottom: 20, left: 30, right: 10),
                child: Row(
                children: <Widget>[
                  Expanded(child: 
                    Text(
                      'Item',
                      style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, ),
                      ),
                  ),
                  Container(width: 2,),
                  Container(

                    child:DropdownButton<String>(
                      value: dropdownValue,

                       onChanged: (String newValue) {
                        // This set state is trowing an error
                        setState((){
                          dropdownValue = newValue;
                        });
                      },

                      items: <String>['Fertilizers', 'Bags', 'Spray', 'Equipments']
                      .map<DropdownMenuItem<String>>((String value) {
                        return DropdownMenuItem<String>(
                          value: value,
                          child: new Text(value),
                        );
                      })
                      .toList(),        
                    ),

                  ),
                ],
              )),  

            Padding( 
                padding: EdgeInsets.only(top:5, bottom: 5, left: 30, right: 10),
                child: Row(
                children: <Widget>[
                  Expanded(child: 
                    Text(
                      'Quantity',
                      style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, ),
                      ),
                  ),
                  Container(width: 2,),
                  Expanded(child: TextField(
                    keyboardType: TextInputType.number,
                    decoration: InputDecoration(
                        labelText: 'Quantity',
                        hintText: 'Enter Cost Quantity',
                        border:OutlineInputBorder(borderRadius: BorderRadius.circular(5.0))
                    ),
                  )),  
                ],
              )),  

            Padding(
              padding: const EdgeInsets.only(left: 10, right: 10, top: 10),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: <Widget>[
                  RaisedButton(
                    color: Colors.blue,
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                    child: Text(
                      'Add',
                      style: TextStyle(fontSize: 18.0, color: Colors.white),
                    ),
                  ),
                  SizedBox(
                    width: 20,
                  ),
                  RaisedButton(
                    color: Colors.red,
                    onPressed: () {
                      Navigator.pop(context);
                      // Navigator.of(context).push(MaterialPageRoute(builder: (context) => StockPage()));
                    },
                    child: Text(
                      'Cancel!',
                      style: TextStyle(fontSize: 18.0, color: Colors.white),
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
    showDialog(context: context, builder: (BuildContext context) => simpleDialog);  


}


// Dropdown Menu Class below


导入'dart:async';
进口“包装:颤振/材料.省道”;
导入“package:erg_app/ProfilePage.dart”;
void main()=>runApp(
材料聚丙烯(
debugShowCheckedModeBanner:false,
主页:StockPage(),
)
);
类StockPage扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“库存数据”,
主题:主题数据(
主样本:颜色。绿色,
),
首页:库存清单(),
);
}
}
类StockInventory扩展了StatefulWidget{
StockInventory({Key}):super(Key:Key);//查找含义
@凌驾
_StockInventoryState createState()=>\u StockInventoryState();
}
类_StockInventoryState扩展了状态{
列出产品清单;
列出所选产品;
布尔排序;
@凌驾
void initState(){
排序=假;
选定产品=[];
products=products.getProducts();
super.initState();
}
onSortColum(整数列索引,布尔升序){
如果(columnIndex==0){
if(升序){
products.sort((a,b)=>a.name.compareTo(b.name));
}否则{
products.sort((a,b)=>b.name.compareTo(a.name));
}
}
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:新中心(子项:新文本(“每日盘点”,textAlign:textAlign.Center)),
自动嵌入:false,
iconTheme:IconThemeData(颜色:Colors.white),
背景颜色:颜色。绿色,),
主体:容器(
子:ListView(
儿童:[
容器(
边距:仅限常量边集(右:20,上:20),
子对象:对齐(
对齐:对齐。右下角,
孩子:升起按钮(
填充:从LTRB(14,10,14,10)开始的边缘设置,
颜色:颜色。绿色,
子项:文本(“盘点”,样式:TextStyle(颜色:Colors.white,fontwweight:fontwweight.bold,fontSize:14),
已按下:(){
//Navigator.of(context).push(materialpage(builder:(context)=>ProfilePage());
showSimpleCustomDialog(上下文);
},
形状:圆形矩形边框(
边界半径:边界半径。圆形(50),
),
),
),
),
容器(
填充:仅限边缘设置(顶部:30,底部:30),
子:数据表(
排序:排序,
sortColumnIndex:0,
栏目:[
数据列(
标签:文本(“S/No”,样式:TextStyle(fontSize:16)),
数字:false,
),
数据列(
标签:文本(“项目”,样式:TextStyle(fontSize:16)),
数字:false,
onSort:(列索引,升序){
设置状态(){
排序=!排序;
});
onSortColum(列索引,升序);
}),
数据列(
标签:文本(“QtyInStock”,样式:TextStyle(fontSize:16)),
数字:false,
),
数据列(
标签:文本(“单位”,样式:TextStyle(fontSize:16)),
数字:false,
),
],
行:产品
.地图(
(产品)=>DataRow(
已选:已选产品。包含(产品),
单元格:[
数据单元(
文本(产品计数),
onTap:(){
打印('Selected${product.count}');
},
),
数据单元(
文本(产品名称),
onTap:(){
打印('Selected${product.name}');
},
),
数据单元(
文本(产品项数量),
onTap:(){
打印('Selected${product.itemqty}');
},
),
数据单元(
文本(产品项数量),
onTap:(){
打印('Selected${product.itemqty}');
},
),
]),
).toList(),
),          
),
容器(
儿童:中心(
孩子:升起按钮(
填充:从LTRB(80,10,80,10)开始的边缘设置,
颜色:颜色。绿色,
儿童:Te
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
      debugShowCheckedModeBanner: false,
      home: StockPage(),
    ));

class StockPage extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Inventory Data',
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      home: StockInventory(),
    );
  }
}

class StockInventory extends StatefulWidget {
  StockInventory({Key key}) : super(key: key); //Find out meaning

  @override
  _StockInventoryState createState() => _StockInventoryState();
}

class _StockInventoryState extends State<StockInventory> {
  List<Products> products;
  List<Products> selectedProducts;
  bool sort;

  @override
  void initState() {
    super.initState();
    sort = false;
    selectedProducts = [];
    products = Products.getProducts();
  }

  onSortColum(int columnIndex, bool ascending) {
    if (columnIndex == 0) {
      if (ascending) {
        products.sort((a, b) => a.name.compareTo(b.name));
      } else {
        products.sort((a, b) => b.name.compareTo(a.name));
      }
    }
  }

  void showSimpleCustomDialog(BuildContext context) {
    String dropdownValue ;

    // TextEditingController _controller = TextEditingController(text: dropdownValue);

      AlertDialog simpleDialog1 = AlertDialog(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10.0))),
        content: StatefulBuilder(
          builder :(BuildContext context, StateSetter setState) {
              return Container(
        height: 300.0,
        width: 300.0,

        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
                padding:
                    EdgeInsets.only(top: 20, bottom: 20, left: 30, right: 10),
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: Text(
                        'Item',
                        style: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    Container(
                      width: 2,
                    ),
                    Container(
                      child: DropdownButton<String>(
                        hint: Text('Enter value'),
                        value: dropdownValue,
                        onChanged: (String newValue) {
                          // This set state is trowing an error
                          setState(() {
                            dropdownValue = newValue;
                          });
                        },
                        items: <String>[
                          'Fertilizers',
                          'Bags',
                          'Spray',
                          'Equipments'
                        ].map<DropdownMenuItem<String>>((String value) {
                          return DropdownMenuItem<String>(
                            value: value,
                            child: new Text(value),
                          );
                        }).toList(),
                      ),
                    ),
                  ],
                )),
            Padding(
                padding:
                    EdgeInsets.only(top: 5, bottom: 5, left: 30, right: 10),
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: Text(
                        'Quantity',
                        style: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    Container(
                      width: 2,
                    ),
                    Expanded(
                        child: TextField(
                      keyboardType: TextInputType.number,
                      decoration: InputDecoration(
                          labelText: 'Quantity',
                          hintText: 'Enter Cost Quantity',
                          border: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(5.0))),
                    )),
                  ],
                )),
            Padding(
              padding: const EdgeInsets.only(left: 10, right: 10, top: 10),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: <Widget>[
                  RaisedButton(
                    color: Colors.blue,
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                    child: Text(
                      'Add',
                      style: TextStyle(fontSize: 18.0, color: Colors.white),
                    ),
                  ),
                  SizedBox(
                    width: 20,
                  ),
                  RaisedButton(
                    color: Colors.red,
                    onPressed: () {
                      Navigator.pop(context);
                      // Navigator.of(context).push(MaterialPageRoute(builder: (context) => StockPage()));
                    },
                    child: Text(
                      'Cancel!',
                      style: TextStyle(fontSize: 18.0, color: Colors.white),
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      );
          }
        ),
      );

    /* Dialog simpleDialog = Dialog(

      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child:
    ); */
    showDialog(
        context: context, builder: (BuildContext context) => simpleDialog1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: new Center(
            child: new Text('Daily Stock Taking', textAlign: TextAlign.center)),
        automaticallyImplyLeading: false,
        iconTheme: IconThemeData(color: Colors.white),
        backgroundColor: Colors.green,
      ),
      body: Container(
        child: ListView(
          children: <Widget>[
            Container(
              margin: const EdgeInsets.only(right: 20, top: 20),
              child: Align(
                alignment: Alignment.bottomRight,
                child: RaisedButton(
                  padding: EdgeInsets.fromLTRB(14, 10, 14, 10),
                  color: Colors.green,
                  child: Text(
                    "Take Inventory",
                    style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: 14),
                  ),
                  onPressed: () {
                    // Navigator.of(context).push(MaterialPageRoute(builder: (context) => ProfilePage()));
                    showSimpleCustomDialog(context);
                  },
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(50),
                  ),
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.only(top: 30, bottom: 30),
              child: DataTable(
                sortAscending: sort,
                sortColumnIndex: 0,
                columns: [
                  DataColumn(
                    label: Text("S/No", style: TextStyle(fontSize: 16)),
                    numeric: false,
                  ),
                  DataColumn(
                      label: Text("Item", style: TextStyle(fontSize: 16)),
                      numeric: false,
                      onSort: (columnIndex, ascending) {
                        setState(() {
                          sort = !sort;
                        });
                        onSortColum(columnIndex, ascending);
                      }),
                  DataColumn(
                    label: Text("QtyInStock", style: TextStyle(fontSize: 16)),
                    numeric: false,
                  ),
                  DataColumn(
                    label: Text("Unit", style: TextStyle(fontSize: 16)),
                    numeric: false,
                  ),
                ],
                rows: products
                    .map(
                      (product) => DataRow(
                          selected: selectedProducts.contains(product),
                          cells: [
                            DataCell(
                              Text(product.count),
                              onTap: () {
                                print('Selected ${product.count}');
                              },
                            ),
                            DataCell(
                              Text(product.name),
                              onTap: () {
                                print('Selected ${product.name}');
                              },
                            ),
                            DataCell(
                              Text(product.itemqty),
                              onTap: () {
                                print('Selected ${product.itemqty}');
                              },
                            ),
                            DataCell(
                              Text(product.itemqty),
                              onTap: () {
                                print('Selected ${product.itemqty}');
                              },
                            ),
                          ]),
                    )
                    .toList(),
              ),
            ),
            Container(
              child: Center(
                child: RaisedButton(
                  padding: EdgeInsets.fromLTRB(80, 10, 80, 10),
                  color: Colors.green,
                  child: Text(
                    "Post Inventory",
                    style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: 14),
                  ),
                  onPressed: () {
                    Navigator.of(context).push(
                        MaterialPageRoute(builder: (context) => ProfilePage()));
                  },
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(50),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class Products {
  String count;
  String name;
  String measuringunit;
  String itemqty;
  Products({this.count, this.name, this.itemqty, this.measuringunit});

  static List<Products> getProducts() {
    return <Products>[
      Products(
        count: "1",
        name: "NPK Fertilizer",
        itemqty: "50",
        measuringunit: "bag",
      ),
      Products(
        count: "2",
        name: "Urea Fertilizer",
        itemqty: "560",
        measuringunit: "bag",
      ),
      Products(
        count: "3",
        name: "Spray",
        itemqty: "150",
        measuringunit: "bottles",
      ),
    ];
  }
}

class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}