BottomBar.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import 'package:douyin_demo/main.dart';
  2. import 'package:douyin_demo/pages/CameraPage/CameraMain.dart';
  3. import 'package:douyin_demo/pages/FaceDetect/FaceDetection.dart';
  4. import 'package:douyin_demo/pages/loadData/loadData.dart';
  5. import 'package:douyin_demo/pages/sameCity/SameCityPage.dart';
  6. import 'package:douyin_demo/pages/selfHome/HomePage.dart';
  7. import 'package:douyin_demo/providers/CameraProvider.dart';
  8. import 'package:douyin_demo/providers/PostsGalleryProvider.dart';
  9. import 'package:douyin_demo/providers/RecommendProvider.dart';
  10. import 'package:flutter/material.dart';
  11. import 'package:provider/provider.dart';
  12. // class BtmBar extends StatelessWidget {
  13. // const BtmBar({Key key}) : super(key: key);
  14. // @override
  15. // Widget build(BuildContext context) {
  16. // // RecommendProvider provider = Provider.of<RecommendProvider>(context);
  17. // return Container(
  18. // child: Row(
  19. // mainAxisAlignment: MainAxisAlignment.spaceAround,
  20. // children: <Widget>[
  21. // getBtmTextWidget("首页", true),
  22. // getBtmTextWidget("同城", false),
  23. // AddIcon(),
  24. // getBtmTextWidget("消息", false),
  25. // getBtmTextWidget("我", false),
  26. // ],
  27. // ),
  28. // );
  29. // }
  30. // }
  31. class BtmBar extends StatefulWidget {
  32. BtmBar({Key key, this.selectIndex}) : super(key: key);
  33. final int selectIndex;
  34. _BtmBarState createState() => _BtmBarState();
  35. }
  36. class _BtmBarState extends State<BtmBar> {
  37. List<bool> selected = List<bool>();
  38. List<String> selectItems = List<String>();
  39. @override
  40. void initState() {
  41. super.initState();
  42. for (var i = 0; i < 4; i++) {
  43. selected.add(false);
  44. }
  45. selected[widget.selectIndex] = true;
  46. }
  47. @override
  48. void dispose() {
  49. // _controller.dispose();
  50. super.dispose();
  51. }
  52. tapItem(index) {
  53. // selected=List<bool>();
  54. // for (var i = 0; i < 4; i++) {
  55. // selected.add(false);
  56. // }
  57. // selected[index]=true;
  58. // setState(() {
  59. // selected=selected;
  60. // });
  61. switch (index) {
  62. // case 0:
  63. // Navigator.pushAndRemoveUntil(
  64. // context,
  65. // MaterialPageRoute(
  66. // builder: (context) => MyHomePage(
  67. // selIndex: index,
  68. // )),
  69. // ModalRoute.withName("/Home"));
  70. // break;
  71. case 1:
  72. Navigator.pushAndRemoveUntil(
  73. context,
  74. MaterialPageRoute(
  75. builder: (context) => MultiProvider(
  76. providers: [
  77. ChangeNotifierProvider(
  78. builder: (context) => PostsGalleryProvider(),
  79. )
  80. ],
  81. child: SameCityMain(
  82. selIndex: index,
  83. ))),
  84. ModalRoute.withName("/sameCity"));
  85. break;
  86. case 2:
  87. Navigator.pushAndRemoveUntil(
  88. context,
  89. MaterialPageRoute(
  90. builder: (context) => SelfHomePage()),
  91. ModalRoute.withName("/selfHome"));
  92. break;
  93. case 3:
  94. Navigator.of(context).push(MaterialPageRoute(
  95. builder: (BuildContext context) {
  96. return MultiProvider(
  97. providers: [
  98. ChangeNotifierProvider(
  99. builder: (_) => CameraProvider(),
  100. )
  101. ],
  102. child: CameraPage(
  103. // rpx: MediaQuery.of(context).size.width / 750,
  104. )
  105. );
  106. },
  107. fullscreenDialog: true
  108. ));
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. @override
  115. Widget build(BuildContext context) {
  116. // RecommendProvider provider = Provider.of<RecommendProvider>(context);
  117. double rpx = MediaQuery.of(context).size.width / 750;
  118. return Container(
  119. child: Row(
  120. mainAxisAlignment: MainAxisAlignment.spaceAround,
  121. children: <Widget>[
  122. Expanded(
  123. flex: 1,
  124. child: getBtmTextWidget("首页", selected[0], () {
  125. tapItem(0);
  126. }, rpx)),
  127. Expanded(
  128. flex: 1,
  129. child: getBtmTextWidget("同城", selected[1], () {
  130. tapItem(1);
  131. }, rpx)),
  132. Expanded(flex: 1, child: AddIcon(tapItem:(){ tapItem(3); },)),
  133. Expanded(
  134. flex: 1,
  135. child: getBtmTextWidget("消息", selected[2], () {
  136. tapItem(2);
  137. }, rpx)),
  138. Expanded(
  139. flex: 1,
  140. child: getBtmTextWidget("我", selected[3], () {
  141. tapItem(3);
  142. }, rpx)),
  143. ],
  144. ),
  145. );
  146. }
  147. }
  148. getBtmTextWidget(String content, bool ifSelected, tapFunc, double rpx) {
  149. return FlatButton(
  150. onPressed: () {
  151. tapFunc();
  152. },
  153. child: Text("$content",
  154. style: ifSelected
  155. ? TextStyle(
  156. fontSize: 30 * rpx,
  157. color: Colors.white,
  158. fontWeight: FontWeight.w900)
  159. : TextStyle(
  160. fontSize: 30 * rpx,
  161. color: Colors.grey[600],
  162. fontWeight: FontWeight.w900)));
  163. }
  164. class AddIcon extends StatelessWidget {
  165. const AddIcon({Key key,@required this.tapItem}) : super(key: key);
  166. final VoidCallback tapItem;
  167. @override
  168. Widget build(BuildContext context) {
  169. double rpx = MediaQuery.of(context).size.width / 750;
  170. double iconHeight = 55 * rpx;
  171. double totalWidth = 90 * rpx;
  172. double eachSide = 5 * rpx;
  173. return Container(
  174. // decoration: BoxDecoration(),
  175. padding: EdgeInsets.symmetric(horizontal: 30 * rpx),
  176. height: iconHeight,
  177. width: 150 * rpx,
  178. child: FlatButton(
  179. padding: EdgeInsets.all(0),
  180. onPressed: (){tapItem();},
  181. child: Stack(
  182. children: <Widget>[
  183. Positioned(
  184. height: iconHeight,
  185. width: totalWidth - eachSide,
  186. child: Container(
  187. decoration: BoxDecoration(
  188. color: Colors.cyan, borderRadius: BorderRadius.circular(10)),
  189. ),
  190. ),
  191. Positioned(
  192. height: iconHeight,
  193. width: totalWidth - eachSide,
  194. right: 0,
  195. child: Container(
  196. decoration: BoxDecoration(
  197. color: Colors.redAccent,
  198. borderRadius: BorderRadius.circular(10)),
  199. ),
  200. ),
  201. Positioned(
  202. height: iconHeight,
  203. width: totalWidth - eachSide * 2,
  204. right: eachSide,
  205. child: Container(
  206. decoration: BoxDecoration(
  207. color: Colors.white, borderRadius: BorderRadius.circular(10)),
  208. child: Icon(Icons.add),
  209. ),
  210. ),
  211. ],
  212. )
  213. ),
  214. );
  215. }
  216. }