|
1 | 1 | import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_demo/model/common_model.dart'; |
| 3 | +import 'package:flutter_demo/model/grid_nav_model.dart'; |
| 4 | +import 'package:flutter_demo/widget/webview.dart'; |
2 | 5 |
|
3 | 6 | class GridNav extends StatelessWidget { |
| 7 | + final GridNavModel? gridNavModel; |
| 8 | + |
| 9 | + const GridNav({Key? key, this.gridNavModel}) : super(key: key); |
| 10 | + |
4 | 11 | @override |
5 | 12 | Widget build(BuildContext context) { |
6 | | - return Text('data'); |
| 13 | + return PhysicalModel( |
| 14 | + color: Colors.transparent, |
| 15 | + borderRadius: BorderRadius.circular(6), |
| 16 | + clipBehavior: Clip.antiAlias, |
| 17 | + child: Column( |
| 18 | + children: _gridNavItems(context), |
| 19 | + )); |
| 20 | + } |
| 21 | + |
| 22 | + _gridNavItems(BuildContext ctx) { |
| 23 | + List<Widget> items = []; |
| 24 | + if (gridNavModel == null) return items; |
| 25 | + |
| 26 | + if (gridNavModel?.hotel != null) { |
| 27 | + items.add(_gridNavItem(ctx, gridNavModel!.hotel, true)); |
| 28 | + } |
| 29 | + |
| 30 | + if (gridNavModel!.flight != null) { |
| 31 | + items.add(_gridNavItem(ctx, gridNavModel!.flight, false)); |
| 32 | + } |
| 33 | + if (gridNavModel!.travel != null) { |
| 34 | + items.add(_gridNavItem(ctx, gridNavModel!.travel, false)); |
| 35 | + } |
| 36 | + |
| 37 | + return items; |
| 38 | + } |
| 39 | + |
| 40 | + Widget _gridNavItem(BuildContext ctx, GridNavItem model, bool first) { |
| 41 | + List<Widget> items = []; |
| 42 | + items.add(_mainItem(ctx, model.mainItem)); |
| 43 | + |
| 44 | + items.add(_doubleItem(ctx, model.item1, model.item2)); |
| 45 | + |
| 46 | + items.add(_doubleItem(ctx, model.item3, model.item4)); |
| 47 | + |
| 48 | + List<Widget> expandItems = []; |
| 49 | + items.forEach((element) { |
| 50 | + expandItems.add(Expanded( |
| 51 | + child: element, |
| 52 | + flex: 1, |
| 53 | + )); |
| 54 | + }); |
| 55 | + |
| 56 | + Color startCor = Color(int.parse('0xff' + model.startColor)); |
| 57 | + Color endCor = Color(int.parse('0xff' + model.endColor)); |
| 58 | + |
| 59 | + return Container( |
| 60 | + height: 88, |
| 61 | + margin: first ? null : EdgeInsets.only(top: 3), |
| 62 | + decoration: |
| 63 | + BoxDecoration(gradient: LinearGradient(colors: [startCor, endCor])), |
| 64 | + child: Row(children: expandItems), |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + Widget _mainItem(BuildContext ctx, CommonModel model) { |
| 69 | + return GestureDetector( |
| 70 | + onTap: () { |
| 71 | + Navigator.push(ctx, MaterialPageRoute(builder: (BuildContext ctx) { |
| 72 | + return WebView( |
| 73 | + url: model.url, |
| 74 | + statusBarColor: model.statusBarColor, |
| 75 | + title: model.title, |
| 76 | + hideAppBar: model.hideAppBar, |
| 77 | + backForbid: false); |
| 78 | + })); |
| 79 | + }, |
| 80 | + child: Stack( |
| 81 | + alignment: AlignmentDirectional.topCenter, |
| 82 | + children: [ |
| 83 | + Image.network(model.icon, |
| 84 | + fit: BoxFit.contain, |
| 85 | + height: 88, |
| 86 | + width: 121, |
| 87 | + alignment: AlignmentDirectional.bottomEnd), |
| 88 | + Container( |
| 89 | + margin: EdgeInsets.only(top: 11), |
| 90 | + child: Text( |
| 91 | + model.title, |
| 92 | + style: TextStyle(fontSize: 14, color: Colors.white), |
| 93 | + ), |
| 94 | + ) |
| 95 | + ], |
| 96 | + )); |
| 97 | + } |
| 98 | + |
| 99 | + Widget _doubleItem(BuildContext ctx, CommonModel model, CommonModel model2) { |
| 100 | + return Column( |
| 101 | + children: [ |
| 102 | + Expanded(child: _item(ctx, model, true)), |
| 103 | + Expanded(child: _item(ctx, model2, true)) |
| 104 | + ], |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + Widget _item(BuildContext ctx, CommonModel model, bool first) { |
| 109 | + BorderSide bs = const BorderSide(width: 0.8, color: Colors.white); |
| 110 | + return FractionallySizedBox( |
| 111 | + widthFactor: 1, |
| 112 | + heightFactor: 1, |
| 113 | + child: Container( |
| 114 | + decoration: BoxDecoration( |
| 115 | + border: Border(left: bs, bottom: first ? bs : BorderSide.none)), |
| 116 | + child: _wrapGesture( |
| 117 | + ctx, |
| 118 | + Center( |
| 119 | + child: Text(model.title, |
| 120 | + textAlign: TextAlign.center, |
| 121 | + style: |
| 122 | + const TextStyle(fontSize: 14, color: Colors.white))), |
| 123 | + model)), |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + Widget _wrapGesture(BuildContext ctx, Widget wd, CommonModel model) { |
| 128 | + return GestureDetector( |
| 129 | + onTap: () { |
| 130 | + Navigator.push(ctx, MaterialPageRoute(builder: (BuildContext ctx) { |
| 131 | + return WebView( |
| 132 | + url: model.url, |
| 133 | + statusBarColor: model.statusBarColor, |
| 134 | + title: model.title, |
| 135 | + hideAppBar: model.hideAppBar, |
| 136 | + backForbid: false); |
| 137 | + })); |
| 138 | + }, |
| 139 | + child: wd); |
7 | 140 | } |
8 | 141 | } |
0 commit comments