bottom_bar.dart 6.3 KB

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