Browse Source

table完成,order抽屉建立

Rice 3 years ago
parent
commit
fed46491d8
7 changed files with 208 additions and 84 deletions
  1. BIN
      images/drawer.jpg
  2. 42 1
      lib/Welcome.dart
  3. 1 1
      lib/main.dart
  4. 4 4
      lib/models/table.dart
  5. 0 69
      lib/order.dart
  6. 86 0
      lib/order/order.dart
  7. 75 9
      lib/table.dart

BIN
images/drawer.jpg


+ 42 - 1
lib/Welcome.dart

@@ -5,7 +5,6 @@ import 'package:provider/provider.dart';
 import 'Staff.dart';
 import 'login.dart';
 import 'models/user.dart';
-import 'order.dart';
 
 class WelcomePage extends StatelessWidget {
   static const routeName = '/welcome';
@@ -43,3 +42,45 @@ class WelcomePage extends StatelessWidget {
     );
   }
 }
+
+class IndexCard extends StatelessWidget {
+  final String title;
+  final String description;
+
+  IndexCard(this.title, this.description);
+
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      padding: EdgeInsets.fromLTRB(12, 12, 12, 0),
+      child: Card(
+          color: Colors.amber,
+          elevation: 10,
+          child: Container(
+            padding: EdgeInsets.fromLTRB(15, 15, 15, 15),
+            child: Column(
+              mainAxisSize: MainAxisSize.min,
+              children: <Widget>[
+                Row(
+                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
+                  children: <Widget>[
+                    Text(
+                      title,
+                      style: TextStyle(fontSize: 30),
+                    ),
+                    Text(title),
+                    Text(title)
+                  ],
+                ),
+                Row(
+                  children: <Widget>[
+                    Icon(Icons.border_color),
+                    Text(description)
+                  ],
+                )
+              ],
+            ),
+          )),
+    );
+  }
+}

+ 1 - 1
lib/main.dart

@@ -1,6 +1,5 @@
 import 'package:flutter/material.dart';
 import 'package:fooddeliveryapp/login.dart';
-import 'package:fooddeliveryapp/order.dart';
 import 'package:fooddeliveryapp/table.dart';
 import 'package:provider/provider.dart';
 
@@ -8,6 +7,7 @@ import 'Staff.dart';
 import 'Welcome.dart';
 import 'models/table.dart';
 import 'models/user.dart';
+import 'order/order.dart';
 
 void main() => runApp(MyApp());
 

+ 4 - 4
lib/models/table.dart

@@ -10,19 +10,19 @@ class TableStatusList with ChangeNotifier {
 
   int size() => _tableStatusMap.length;
 
+  ///如果当前台已开返回true,如果没开则返回false
   bool isopen(int index) {
-    if (_tableStatusMap != null && _tableStatusMap[index] != null)
-      return _tableStatusMap[index].isopen;
-    else
-      return false;
+    return _tableStatusMap.containsKey(index);
   }
 
   addtable(TableStatus tableStatus) {
     _tableStatusMap[tableStatus.id] = tableStatus;
+    notifyListeners();
   }
 
   deletetable(int index) {
     _tableStatusMap.remove(index);
+    notifyListeners();
   }
 }
 

+ 0 - 69
lib/order.dart

@@ -1,69 +0,0 @@
-import 'package:flutter/material.dart';
-
-///Order START
-class IndexCard extends StatelessWidget {
-  final String title;
-  final String description;
-
-  IndexCard(this.title, this.description);
-
-  @override
-  Widget build(BuildContext context) {
-    return Container(
-      padding: EdgeInsets.fromLTRB(12, 12, 12, 0),
-      child: Card(
-          color: Colors.amber,
-          elevation: 10,
-          child: Container(
-            padding: EdgeInsets.fromLTRB(15, 15, 15, 15),
-            child: Column(
-              mainAxisSize: MainAxisSize.min,
-              children: <Widget>[
-                Row(
-                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
-                  children: <Widget>[
-                    Text(
-                      title,
-                      style: TextStyle(fontSize: 30),
-                    ),
-                    Text(title),
-                    Text(title)
-                  ],
-                ),
-                Row(
-                  children: <Widget>[
-                    Icon(Icons.border_color),
-                    Text(description)
-                  ],
-                )
-              ],
-            ),
-          )),
-    );
-  }
-}
-
-class OrderPage extends StatefulWidget {
-  static const routeName = '/order';
-
-  @override
-  State<StatefulWidget> createState() {
-    return _OrderPageState();
-  }
-}
-
-class _OrderPageState extends State<OrderPage> {
-  @override
-  Widget build(BuildContext context) {
-    return Scaffold(
-      appBar: AppBar(title: Text("点单页面")),
-      body: Center(
-        child: Column(
-          children: <Widget>[Text("order页面")],
-        ),
-      ),
-    );
-  }
-}
-
-/// order END

+ 86 - 0
lib/order/order.dart

@@ -0,0 +1,86 @@
+import 'package:flutter/material.dart';
+
+///Order START
+class OrderPage extends StatefulWidget {
+  static const routeName = '/order';
+  final int index;
+  //构造函数 同时传入桌号
+  OrderPage({Key key, @required this.index}) : super(key: key);
+
+  @override
+  State<StatefulWidget> createState() {
+    print("[桌点餐详情]" + index.toString());
+    return _OrderPageState();
+  }
+}
+
+class _OrderPageState extends State<OrderPage> {
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(title: Text("点单页面")),
+      drawer: Drawer(
+        // Add a ListView to the drawer. This ensures the user can scroll
+        // through the options in the drawer if there isn't enough vertical
+        // space to fit everything.
+        child: ListView(
+          // Important: Remove any padding from the ListView.
+          padding: EdgeInsets.zero,
+          children: <Widget>[
+            DrawerHeader(
+              child: Column(
+                children: <Widget>[
+                  Padding(
+                    padding: const EdgeInsets.fromLTRB(0,60,0,0),
+                    child: Text(
+                      "口之福火锅店",
+                      style: TextStyle(
+                          fontSize: 30,
+                          color: Colors.white,
+                          fontStyle: FontStyle.italic,
+                          fontWeight: FontWeight.bold),
+                    ),
+                  )
+                ],
+              ),
+              decoration: BoxDecoration(
+                color: Colors.red,
+                image: new DecorationImage(
+                  // image: new ExactAssetImage('images/drawer.jpg'),
+                  image: new NetworkImage(
+                      "http://test.ricemarch.com:9000/images/timg.jpg"),
+                  fit: BoxFit.cover,
+                ),
+              ),
+            ),
+            ListTile(
+              title: Text('Item 1'),
+              onTap: () {
+                // Update the state of the app
+                // ...
+                // Then close the drawer
+                Navigator.pop(context);
+              },
+            ),
+            ListTile(
+              title: Text('Item 2'),
+              onTap: () {
+                // Update the state of the app
+                // ...
+                // Then close the drawer
+                Navigator.pop(context);
+              },
+            ),
+          ],
+        ),
+      ),
+      body: Center(
+        child: Column(
+          children: <Widget>[Text("order页面")],
+        ),
+      ),
+    );
+  }
+}
+
+/// order END

+ 75 - 9
lib/table.dart

@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:fooddeliveryapp/order/order.dart';
 import 'package:provider/provider.dart';
 
 import 'models/table.dart';
@@ -31,7 +32,7 @@ class _TableState extends State<TablePage> {
             )
           ];
         },
-        body: _getTableItems(tableStatusList),
+        body: _getTableItems(tableStatusList, context),
       ));
     });
   }
@@ -44,7 +45,7 @@ class _TableState extends State<TablePage> {
           Text('目前开台数:' + tableStatusList.size().toString(),
               style: TextStyle(fontSize: 12)),
           Text(
-            '剩余空位:'+(30-tableStatusList.size()).toString(),
+            '剩余空位:' + (30 - tableStatusList.size()).toString(),
             style: TextStyle(fontSize: 10),
           ),
         ],
@@ -56,35 +57,100 @@ class _TableState extends State<TablePage> {
     );
   }
 
-  _getTableItems(tableStatusList) {
+  _getTableItems(TableStatusList tableStatusList, BuildContext context) {
     return GridView.extent(
         maxCrossAxisExtent: 150,
         padding: EdgeInsets.all(4),
         mainAxisSpacing: 4,
         crossAxisSpacing: 4,
-        children: _buildGridTileList(30, tableStatusList));
+        children: _buildGridTileList(30, tableStatusList, context));
   }
 
 /*
 * 单写了一个私有方法,创建指定数量的组件
 * */
-  List<Widget> _buildGridTileList(int count, TableStatusList tableStatusList) {
+  List<Widget> _buildGridTileList(
+      int count, TableStatusList tableStatusList, BuildContext context) {
     List<Widget> containers = [];
+    final statusList = Provider.of<TableStatusList>(context);
     for (var i = 0; i < count; i++) {
       // var image = Image.network('https://picsum.photos/id/$i/150');
       // containers.add(image);
       containers.add(GestureDetector(
-        child: Text(tableStatusList.isopen(i).toString() + "$i"),
+        child: _tableCell(tableStatusList, i),
         onTap: () {
           if (tableStatusList.isopen(i)) {
-            //进行开台
-            print("$i");
+            print("点击该台已开台,台号为=> " + "$i");
+            Navigator.push(
+                context, MaterialPageRoute(builder: (context) => OrderPage(index: i)));
           } else {
-            print("该桌未开台=> " + "$i");
+            print("点击该台号为=> " + "$i");
+            statusList.addtable(TableStatus(i));
+            Navigator.push(
+                context, MaterialPageRoute(builder: (context) => OrderPage(index: i)));
           }
         },
       ));
     }
     return containers;
   }
+
+  _tableCell(TableStatusList tableStatusList, int index) {
+    if (tableStatusList.isopen(index)) {
+      return Container(
+          padding: EdgeInsets.all(2),
+          decoration: BoxDecoration(
+            borderRadius: BorderRadius.all(Radius.circular(10)),
+            color: Colors.green,
+          ),
+          child: Column(
+            children: <Widget>[
+              Row(
+                children: <Widget>[
+                  Icon(
+                    Icons.warning,
+                    color: Colors.white,
+                    size: 30.0,
+                  ),
+                  Text(
+                    index.toString(),
+                    style: TextStyle(fontSize: 15),
+                  )
+                ],
+              ),
+              Icon(Icons.table_chart),
+              Text("已开台"),
+            ],
+          ));
+    } else {
+      return Container(
+          padding: EdgeInsets.all(2),
+          decoration: BoxDecoration(
+            borderRadius: BorderRadius.all(Radius.circular(10)),
+            color: Colors.blue,
+          ),
+          child: Column(
+            children: <Widget>[
+              Row(
+                children: <Widget>[
+                  Icon(
+                    Icons.audiotrack,
+                    color: Colors.white,
+                    size: 30.0,
+                  ),
+                  Text(
+                    index.toString(),
+                    style: TextStyle(fontSize: 15),
+                  )
+                ],
+              ),
+              Icon(
+                Icons.table_chart,
+                color: Colors.white,
+              ),
+              Text("空桌"),
+            ],
+          ));
+    }
+  }
 }