Commit 302c89bb2b2281a5ee3d80226dfc01fb36f19257

Authored by wdn127929
1 parent 8d689f9d

菜单管理 瀑布流布局

@@ -10,6 +10,7 @@ import 'package:one_key/provider/user_model.dart'; @@ -10,6 +10,7 @@ import 'package:one_key/provider/user_model.dart';
10 import 'package:one_key/res/colors.dart'; 10 import 'package:one_key/res/colors.dart';
11 import 'package:one_key/route/navigator_util.dart'; 11 import 'package:one_key/route/navigator_util.dart';
12 import 'package:one_key/utils/event_bus.dart'; 12 import 'package:one_key/utils/event_bus.dart';
  13 +import 'package:one_key/utils/utils.dart';
13 import 'package:one_key/widgets/MyDivider.dart'; 14 import 'package:one_key/widgets/MyDivider.dart';
14 import 'package:one_key/widgets/h_empty_view.dart'; 15 import 'package:one_key/widgets/h_empty_view.dart';
15 import 'package:one_key/widgets/page_exception.dart'; 16 import 'package:one_key/widgets/page_exception.dart';
@@ -17,6 +18,7 @@ import 'package:one_key/widgets/round_button.dart'; @@ -17,6 +18,7 @@ import 'package:one_key/widgets/round_button.dart';
17 import 'package:one_key/widgets/system_app_bar.dart'; 18 import 'package:one_key/widgets/system_app_bar.dart';
18 import 'package:one_key/widgets/v_empty_view.dart'; 19 import 'package:one_key/widgets/v_empty_view.dart';
19 import 'package:provider/provider.dart'; 20 import 'package:provider/provider.dart';
  21 +import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
20 22
21 class MenuManagePage extends StatefulWidget { 23 class MenuManagePage extends StatefulWidget {
22 MenuManagePage({Key key}) : super(key: key); 24 MenuManagePage({Key key}) : super(key: key);
@@ -76,6 +78,10 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -76,6 +78,10 @@ class _MenuManagePageState extends State<MenuManagePage> {
76 showMsg: "加载中,请稍后...", 78 showMsg: "加载中,请稍后...",
77 ); 79 );
78 } else { 80 } else {
  81 + // double cellWidth = (MediaQuery.of(context).size.width -
  82 + // ScreenUtil().setWidth(40 * 2 + 15 * 2) / 2);
  83 + // double desiredCellHeight = ScreenUtil().setWidth(700);
  84 + // double childAspectRatio = cellWidth / desiredCellHeight;
79 return Column(children: [ 85 return Column(children: [
80 Expanded( 86 Expanded(
81 child: ListView.builder( 87 child: ListView.builder(
@@ -123,55 +129,105 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -123,55 +129,105 @@ class _MenuManagePageState extends State<MenuManagePage> {
123 ), 129 ),
124 ], 130 ],
125 ), 131 ),
126 - GridView.builder(  
127 - controller: _controller,  
128 - physics: NeverScrollableScrollPhysics(),  
129 - padding: EdgeInsets.symmetric(  
130 - vertical: ScreenUtil().setWidth(40)),  
131 - shrinkWrap: true,  
132 - cacheExtent: ScreenUtil().setWidth(0),  
133 - itemCount: menuManageProvider 132 + StaggeredGridView.countBuilder(
  133 + padding: EdgeInsets.symmetric(
  134 + vertical: ScreenUtil().setWidth(40)),
  135 + shrinkWrap: true,
  136 + crossAxisCount: 4,
  137 + itemCount: menuManageProvider
  138 + .menuModel[indexOut].cookbooklist.length,
  139 + physics: NeverScrollableScrollPhysics(),
  140 + itemBuilder:
  141 + (BuildContext context, int index) {
  142 + MenuSunModel model = menuManageProvider
134 .menuModel[indexOut] 143 .menuModel[indexOut]
135 - .cookbooklist  
136 - .length,  
137 - gridDelegate:  
138 - SliverGridDelegateWithFixedCrossAxisCount(  
139 - crossAxisCount: 2,  
140 - childAspectRatio: 80 / 56,  
141 - mainAxisSpacing:  
142 - ScreenUtil().setWidth(15 * 2),  
143 - crossAxisSpacing:  
144 - ScreenUtil().setWidth(15 * 2)),  
145 - itemBuilder:  
146 - (BuildContext context, int index) {  
147 - MenuSunModel model = menuManageProvider  
148 - .menuModel[indexOut]  
149 - .cookbooklist[index];  
150 - return Container(  
151 - decoration: BoxDecoration(  
152 - color: index % 2 == 0  
153 - ? Color.fromRGBO(  
154 - 247, 230, 230, 1)  
155 - : Color.fromRGBO(  
156 - 234, 236, 252, 1),  
157 - borderRadius: BorderRadius.circular(  
158 - ScreenUtil().setWidth(10))),  
159 - child: model.image != null  
160 - ? ClipRRect(  
161 - borderRadius:  
162 - BorderRadius.circular(  
163 - ScreenUtil()  
164 - .setWidth(10)),  
165 - child: CachedNetworkImage(  
166 - imageUrl: model.image,  
167 - fit: BoxFit.cover,  
168 - width: ScreenUtil()  
169 - .setWidth(30 * 2),  
170 - height: ScreenUtil()  
171 - .setWidth(30 * 2), 144 + .cookbooklist[index];
  145 + double cellWidth = ((MediaQuery.of(context)
  146 + .size
  147 + .width -
  148 + ScreenUtil()
  149 + .setWidth(40 * 2 + 15 * 2)) /
  150 + 2);
  151 + return model.image != null
  152 + ? Stack(children: [
  153 + Column(
  154 + crossAxisAlignment:
  155 + CrossAxisAlignment.start,
  156 + children: [
  157 + Container(
  158 + decoration: BoxDecoration(
  159 + borderRadius:
  160 + BorderRadius.circular(
  161 + ScreenUtil()
  162 + .setWidth(
  163 + 10))),
  164 + child: ClipRRect(
  165 + borderRadius: BorderRadius
  166 + .circular(ScreenUtil()
  167 + .setWidth(10)),
  168 + child: CachedNetworkImage(
  169 + imageUrl: model.image,
  170 + fit: BoxFit.cover,
  171 + width: cellWidth,
  172 + height: ScreenUtil()
  173 + .setWidth(210),
  174 + ),
  175 + )),
  176 + VEmptyView(15),
  177 + Text(
  178 + model.name,
  179 + style: TextStyle(
  180 + color: MyColours
  181 + .color_333333,
  182 + fontSize: ScreenUtil()
  183 + .setSp(34),
  184 + fontWeight:
  185 + FontWeight.bold),
172 ), 186 ),
173 - )  
174 - : Container( 187 + VEmptyView(20),
  188 + Text(
  189 + '${model.price}元/${model.unit}',
  190 + style: TextStyle(
  191 + color: MyColours
  192 + .color_333333,
  193 + fontSize: ScreenUtil()
  194 + .setSp(28),
  195 + ))
  196 + ],
  197 + ),
  198 + Positioned(
  199 + bottom:
  200 + ScreenUtil().setWidth(14),
  201 + right:
  202 + ScreenUtil().setWidth(20),
  203 + child: model.status == '1'
  204 + ? SizedBox()
  205 + : Image.asset(
  206 + Utils.getImgPath(
  207 + 'stop-sell'),
  208 + width: ScreenUtil()
  209 + .setWidth(82),
  210 + height: ScreenUtil()
  211 + .setWidth(52),
  212 + )),
  213 + ])
  214 + : Stack(children: [
  215 + Container(
  216 + width: cellWidth,
  217 + height:
  218 + ScreenUtil().setWidth(210),
  219 +
  220 + decoration: BoxDecoration(
  221 + color: index % 2 == 0
  222 + ? Color.fromRGBO(
  223 + 247, 230, 230, 1)
  224 + : Color.fromRGBO(
  225 + 234, 236, 252, 1),
  226 + borderRadius:
  227 + BorderRadius.circular(
  228 + ScreenUtil()
  229 + .setWidth(10))),
  230 + child: Container(
175 padding: EdgeInsets.symmetric( 231 padding: EdgeInsets.symmetric(
176 horizontal: ScreenUtil() 232 horizontal: ScreenUtil()
177 .setWidth(20)), 233 .setWidth(20)),
@@ -203,17 +259,57 @@ class _MenuManagePageState extends State<MenuManagePage> { @@ -203,17 +259,57 @@ class _MenuManagePageState extends State<MenuManagePage> {
203 ], 259 ],
204 ), 260 ),
205 ), 261 ),
206 - );  
207 - }) 262 +
  263 + // VEmptyView(15),
  264 + // Text(
  265 + // ' ',
  266 + // style: TextStyle(
  267 + // color: MyColours.color_333333,
  268 + // fontSize:
  269 + // ScreenUtil().setSp(34),
  270 + // fontWeight: FontWeight.bold),
  271 + // ),
  272 + // VEmptyView(20),
  273 + // Text(' ',
  274 + // style: TextStyle(
  275 + // color: MyColours.color_333333,
  276 + // fontSize:
  277 + // ScreenUtil().setSp(28),
  278 + // ))
  279 + ),
  280 + Positioned(
  281 + bottom:
  282 + ScreenUtil().setWidth(46),
  283 + right:
  284 + ScreenUtil().setWidth(20),
  285 + child: model.status == '1'
  286 + ? SizedBox()
  287 + : Image.asset(
  288 + Utils.getImgPath(
  289 + 'stop-sell'),
  290 + width: ScreenUtil()
  291 + .setWidth(82),
  292 + height: ScreenUtil()
  293 + .setWidth(52),
  294 + )),
  295 + ]);
  296 + },
  297 + staggeredTileBuilder: (int index) =>
  298 + new StaggeredTile.count(
  299 + 2,
  300 + menuManageProvider
  301 + .menuModel[indexOut]
  302 + .cookbooklist[index]
  303 + .image !=
  304 + null
  305 + ? ScreenUtil().setWidth(4.2)
  306 + : ScreenUtil().setWidth(2.85)),
  307 + mainAxisSpacing:
  308 + ScreenUtil().setWidth(15 * 2),
  309 + crossAxisSpacing:
  310 + ScreenUtil().setWidth(15 * 2),
  311 + ),
208 ], 312 ],
209 - // onRefresh: () async {  
210 - // // offset = 0;  
211 - // // getMessage(showLoading: false);  
212 - // },  
213 - // onLoad: () async {  
214 - // // offset++;  
215 - // // getMessage(showLoading: false);  
216 - // },  
217 ); 313 );
218 })), 314 })),
219 Row( 315 Row(
@@ -419,6 +419,13 @@ packages: @@ -419,6 +419,13 @@ packages:
419 url: "https://pub.flutter-io.cn" 419 url: "https://pub.flutter-io.cn"
420 source: hosted 420 source: hosted
421 version: "1.1.0" 421 version: "1.1.0"
  422 + flutter_staggered_grid_view:
  423 + dependency: "direct main"
  424 + description:
  425 + name: flutter_staggered_grid_view
  426 + url: "https://pub.flutter-io.cn"
  427 + source: hosted
  428 + version: "0.4.1"
422 flutter_statusbarcolor: 429 flutter_statusbarcolor:
423 dependency: "direct main" 430 dependency: "direct main"
424 description: 431 description:
@@ -133,6 +133,7 @@ dependencies: @@ -133,6 +133,7 @@ dependencies:
133 flutter_native_image: ^0.0.6+1 133 flutter_native_image: ^0.0.6+1
134 #更新apk 134 #更新apk
135 flutter_app_update: ^1.0.2 135 flutter_app_update: ^1.0.2
  136 + flutter_staggered_grid_view: ^0.4.1
136 # webview 137 # webview
137 # webview_flutter: ^2.0.13 138 # webview_flutter: ^2.0.13
138 webview_flutter: 139 webview_flutter: