YSTabBar.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_wallet/exchange/YSExchange.dart';
  3. import 'package:flutter_wallet/find/YSFind.dart';
  4. import 'package:flutter_wallet/setting/YSSetting.dart';
  5. import 'package:flutter_wallet/shop/YSShop.dart';
  6. import 'package:flutter_wallet/wallet/YSWallet.dart';
  7. import 'package:provider/provider.dart';
  8. import '../generated/l10n.dart';
  9. import '../tools/YSAlertView.dart';
  10. import '../tools/YSColors.dart';
  11. import '../tools/YSNetWork.dart';
  12. import '../tools/YSTools.dart';
  13. class YSTabBar extends StatefulWidget {
  14. const YSTabBar({Key? key}) : super(key: key);
  15. @override
  16. YSTabBarState createState() => YSTabBarState();
  17. }
  18. class YSTabBarState extends State<YSTabBar> {
  19. final PageController _pageController = PageController();
  20. static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
  21. int _index = 0;
  22. int _isRefresh = 0;
  23. static const List<Widget> _widgetOptions = <Widget>[
  24. YSWallet(),
  25. YSShop(),
  26. YSExchange(),
  27. YSFind(),
  28. YSSetting()
  29. ];
  30. @override
  31. void dispose() {
  32. _pageController.dispose();
  33. super.dispose();
  34. }
  35. @override
  36. void initState() {
  37. _getVersionData();
  38. super.initState();
  39. }
  40. _getVersionData() async{
  41. YSNetWork.ysRequestHttp(context, type: RequestType.post, api: 'versions', parameter: {}, successSetter: (dict) async{
  42. List list = dict['data']['list'];
  43. if(list.isNotEmpty){
  44. Map data = list.first;
  45. // PackageInfo packageInfo = await PackageInfo.fromPlatform();
  46. //int.parse(packageInfo.buildNumber)<data['build']&&data['is_force']==1;
  47. getVersionData(context,data);
  48. }
  49. });
  50. }
  51. @override
  52. Widget build(BuildContext context) {
  53. return NotificationListener<CustomerNotification>(
  54. onNotification: (object){
  55. _pageController.jumpToPage(2);
  56. _index = 2;
  57. _isRefresh++;
  58. setState(() {});
  59. return false;
  60. },
  61. child: Scaffold(
  62. backgroundColor: Colors.white,
  63. body:Consumer(
  64. builder: (context,CurrentLocale locale,child) {
  65. return PageView.builder(
  66. controller: _pageController,
  67. itemBuilder: (context,index){
  68. return _widgetOptions[index];
  69. },
  70. itemCount: _widgetOptions.length,
  71. physics: const NeverScrollableScrollPhysics(),
  72. );
  73. }
  74. ),
  75. //_widgetOptions.elementAt(_selectedIndex),
  76. bottomNavigationBar: YSTabBarView(postIndex: (value){
  77. _pageController.jumpToPage(value);
  78. setState(() {});
  79. },index: _index,key: Key('$_isRefresh'),)
  80. ),
  81. );
  82. }
  83. }
  84. class YSTabBarView extends StatefulWidget {
  85. final ValueSetter<int> postIndex;
  86. final int index;
  87. const YSTabBarView({Key? key, required this.postIndex, required this.index}) : super(key: key);
  88. @override
  89. YSTabBarViewState createState() => YSTabBarViewState();
  90. }
  91. class YSTabBarViewState extends State<YSTabBarView> {
  92. int _index = 0;
  93. @override
  94. void initState() {
  95. _index = widget.index;
  96. super.initState();
  97. }
  98. @override
  99. Widget build(BuildContext context) {
  100. List<YSBarItem> _itemArray = [
  101. YSBarItem('编组 5', '编组 5', S.current.BAKEQIANBAO,),
  102. YSBarItem('导航-市场运营', '导航-市场运营', S.current.SHICHANG,),
  103. YSBarItem('编组 7', '编组 7', S.current.DUIHUAN,),
  104. YSBarItem('编组 8', '编组 8', S.current.FAXIAN,),
  105. YSBarItem('编组 9', '编组 9', S.current.SHEZHI,)
  106. ];
  107. return Container(
  108. decoration: BoxDecoration(
  109. color: YSColors.containColor(context),
  110. boxShadow: const [
  111. BoxShadow(color: Colors.black12,blurRadius: 5,offset: Offset(0, -5))
  112. ]
  113. ),
  114. height: ystabBarHeight,
  115. width: ysWidth(context),
  116. child: ListView.builder(itemBuilder: (context,index){
  117. YSBarItem item = _itemArray[index];
  118. Color colorValue = _index==index?YSColors.iconColor(context):YSColors.unSelectedColor(context);
  119. return GestureDetector(
  120. onTap: (){
  121. if(item.label.isNotEmpty){
  122. _index = index;
  123. setState(() {});
  124. }
  125. widget.postIndex(index);
  126. },
  127. behavior: HitTestBehavior.opaque,
  128. child: Container(
  129. color: YSColors.tabColor(context),
  130. width: ysWidth(context)/_itemArray.length,
  131. alignment: Alignment.center,
  132. child: item.label.isEmpty?Image.asset(item.image,height: 60,width: 60,):Column(
  133. mainAxisSize: MainAxisSize.min,
  134. children: [//_index==index?item.imageSelected:
  135. Image.asset(YSColors.imageStyle(context, item.image),height: 22,width: 22,color: colorValue,),
  136. Padding(
  137. padding: const EdgeInsets.only(top: 5),
  138. child: Text(item.label, style: TextStyle(fontSize: 11,color: colorValue),),
  139. )
  140. ],
  141. ),
  142. ),
  143. );
  144. },itemCount: _itemArray.length,scrollDirection: Axis.horizontal,),
  145. );
  146. }
  147. }
  148. class YSBarItem{
  149. final String image;
  150. final String imageSelected;
  151. String label = '';
  152. YSBarItem(this.image, this.imageSelected, this.label);
  153. }