BottomBar.dart 5.4 KB

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