Advertisement
Guest User

code2

a guest
Sep 29th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. import 'package:chicksmore_beta/Pages/Food/product/product.dart';
  2. import 'package:chicksmore_beta/Widget/big_text.dart';
  3. import 'package:cloud_firestore/cloud_firestore.dart';
  4. import 'package:flutter/material.dart';
  5.  
  6. class foodPageBodyFood extends StatefulWidget {
  7. const foodPageBodyFood({Key? key}) : super(key: key);
  8.  
  9. @override
  10. _foodPageBodyFoodState createState() => _foodPageBodyFoodState();
  11. }
  12.  
  13. class _foodPageBodyFoodState extends State<foodPageBodyFood> {
  14. int _selectedIndex = 0;
  15. String routeArgs = "";
  16. String foodCatergory = "";
  17.  
  18. @override
  19. void didChangeDependencies() {
  20. routeArgs = ModalRoute.of(context)!.settings.arguments.toString();
  21. //_selectedIndex = int.parse(
  22. // routeArgs.substring(1, 2),
  23. //);
  24. print(routeArgs.toString());
  25. if (_selectedIndex == 0) {
  26. setState(() {
  27. foodCatergory = 'Chop';
  28. });
  29. }
  30. if (_selectedIndex == 1) {
  31. setState(() {
  32. foodCatergory = 'Snacks';
  33. });
  34. }
  35. if (_selectedIndex == 2) {
  36. setState(() {
  37. foodCatergory = 'Sides';
  38. });
  39. }
  40. if (_selectedIndex == 3) {
  41. setState(() {
  42. foodCatergory = 'Noodle';
  43. });
  44. }
  45. if (_selectedIndex == 4) {
  46. setState(() {
  47. foodCatergory = 'Rice';
  48. });
  49. }
  50. if (_selectedIndex == 5) {
  51. setState(() {
  52. foodCatergory = 'Bucket';
  53. });
  54. }
  55. if (_selectedIndex == 6) {
  56. setState(() {
  57. foodCatergory = 'Combo';
  58. });
  59. }
  60. super.didChangeDependencies();
  61. }
  62.  
  63. Widget build(BuildContext context) {
  64. return Container(
  65. height: 600,
  66. child: Row(
  67. children: [
  68. LayoutBuilder(
  69. builder: ((context, constraints) {
  70. return SingleChildScrollView(
  71. child: ConstrainedBox(
  72. constraints: BoxConstraints(minHeight: constraints.maxHeight),
  73. child: IntrinsicHeight(
  74. child: NavigationRail(
  75. labelType: NavigationRailLabelType.all,
  76. selectedIndex: _selectedIndex,
  77. onDestinationSelected: (int index) {
  78. setState(() {
  79. _selectedIndex = index;
  80. print(_selectedIndex);
  81. if (_selectedIndex == 0) {
  82. setState(() {
  83. foodCatergory = 'Chop';
  84. });
  85. }
  86. if (_selectedIndex == 1) {
  87. setState(() {
  88. foodCatergory = 'Snacks';
  89. });
  90. }
  91. if (_selectedIndex == 2) {
  92. setState(() {
  93. foodCatergory = 'Sides';
  94. });
  95. }
  96. if (_selectedIndex == 3) {
  97. setState(() {
  98. foodCatergory = 'Noodle';
  99. });
  100. }
  101. if (_selectedIndex == 4) {
  102. setState(() {
  103. foodCatergory = 'Rice';
  104. });
  105. }
  106. if (_selectedIndex == 5) {
  107. setState(() {
  108. foodCatergory = 'Bucket';
  109. });
  110. }
  111. if (_selectedIndex == 6) {
  112. setState(() {
  113. foodCatergory = 'Combo';
  114. });
  115. }
  116. print(foodCatergory);
  117. });
  118. },
  119. destinations: [
  120. NavigationRailDestination(
  121. icon: const Icon(Icons.food_bank),
  122. label: Text("Chop")),
  123. NavigationRailDestination(
  124. icon: const Icon(Icons.food_bank),
  125. label: Text("Snacks")),
  126. NavigationRailDestination(
  127. icon: const Icon(Icons.food_bank),
  128. label: Text("Sides")),
  129. NavigationRailDestination(
  130. icon: const Icon(Icons.food_bank),
  131. label: Text("Noodle")),
  132. NavigationRailDestination(
  133. icon: const Icon(Icons.food_bank),
  134. label: Text("Rice")),
  135. NavigationRailDestination(
  136. icon: const Icon(Icons.food_bank),
  137. label: Text("Bucket")),
  138. NavigationRailDestination(
  139. icon: const Icon(Icons.food_bank),
  140. label: Text("Combo")),
  141. ],
  142. ),
  143. ),
  144. ),
  145. );
  146. }),
  147. ),
  148. //ContentSpace(context, foodCatergory),
  149. ],
  150. ),
  151. );
  152. }
  153. }
  154.  
  155. class ContentSpace extends StatelessWidget {
  156. final String category;
  157. ContentSpace(BuildContext context, this.category);
  158. final CollectionReference _products =
  159. FirebaseFirestore.instance.collection('foodProduct');
  160.  
  161. @override
  162. Widget build(BuildContext context) {
  163. return Container(
  164. child: StreamBuilder(
  165. stream: _products.snapshots(),
  166. builder: (context, AsyncSnapshot<QuerySnapshot> streamSnapshot) {
  167. if (streamSnapshot.hasData) {
  168. return ListView.builder(
  169. itemCount: streamSnapshot.data!.docs.length,
  170. itemBuilder: (context, index) {
  171. final DocumentSnapshot documentSnapshot =
  172. streamSnapshot.data!.docs[index];
  173. return Container(
  174. margin: const EdgeInsets.all(10),
  175. child: ListTile(
  176. title: Text(documentSnapshot['name']),
  177. subtitle: Text(documentSnapshot['price'].toString()),
  178. trailing: SizedBox(
  179. width: 100,
  180. ),
  181. ),
  182. );
  183. });
  184. }
  185. return SizedBox.shrink();
  186. }),
  187. );
  188. }
  189. }
  190.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement