reap_step_tab_page.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import 'package:flutter/material.dart';
  2. import 'package:lszlgl/base/base_state.dart';
  3. import 'package:lszlgl/config/colors.dart';
  4. import 'package:lszlgl/page/reap_step/reap_step_list_page.dart';
  5. enum StepType {
  6. reap(title: '收获环节'),
  7. stock(title: '库存环节');
  8. const StepType({required this.title});
  9. final String title;
  10. }
  11. class ReapStepTabPageArgs {
  12. final StepType type;
  13. const ReapStepTabPageArgs({required this.type});
  14. }
  15. /// 收获环节
  16. class ReapStepTabPage extends StatefulWidget {
  17. final ReapStepTabPageArgs args;
  18. const ReapStepTabPage({
  19. Key? key,
  20. ReapStepTabPageArgs? args,
  21. }) : args = args ?? const ReapStepTabPageArgs(type: StepType.reap),
  22. super(key: key);
  23. @override
  24. State<ReapStepTabPage> createState() => _ReapStepTabPageState();
  25. }
  26. class _ReapStepTabPageState extends BaseState<ReapStepTabPage> with TickerProviderStateMixin {
  27. late TabController tabCtrl;
  28. late PageController pageCtrl;
  29. late List<String> tabTextList;
  30. late List<Widget> pageList;
  31. @override
  32. void initState() {
  33. super.initState();
  34. tabCtrl = TabController(length: 2, vsync: this);
  35. pageCtrl = PageController();
  36. tabTextList = ['待扦样', '扦样完成'];
  37. pageList = [
  38. ReapStepListPage(type: widget.args.type),
  39. ReapStepListPage(type: widget.args.type, complete: true),
  40. ];
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. return myScaffold(child: buildBody());
  45. }
  46. Widget buildBody() {
  47. return Column(
  48. children: [
  49. myAppBar(title: widget.args.type.title),
  50. buildTab(),
  51. const SizedBox(height: 12),
  52. Expanded(child: buildPage()),
  53. ],
  54. );
  55. }
  56. Widget buildTab() {
  57. return Container(
  58. clipBehavior: Clip.hardEdge,
  59. height: 36,
  60. decoration: const BoxDecoration(
  61. color: Colors.white,
  62. borderRadius: BorderRadius.all(Radius.circular(100)),
  63. border: Border.fromBorderSide(BorderSide(color: Colors.white, width: 1)),
  64. ),
  65. child: TabBar(
  66. controller: tabCtrl,
  67. onTap: (index) {
  68. if ((pageCtrl.page?.toInt() ?? 0) == index) return;
  69. pageCtrl.animateToPage(index, duration: const Duration(milliseconds: 200), curve: Curves.ease);
  70. },
  71. tabAlignment: TabAlignment.center,
  72. indicator: const BoxDecoration(
  73. borderRadius: BorderRadius.all(Radius.circular(100)),
  74. color: MyColor.c_28A3ED,
  75. ),
  76. indicatorSize: TabBarIndicatorSize.tab,
  77. dividerHeight: 0,
  78. labelStyle: const TextStyle(
  79. fontSize: 14,
  80. fontWeight: FontWeight.w500,
  81. color: Colors.white,
  82. ),
  83. unselectedLabelStyle: const TextStyle(
  84. fontSize: 14,
  85. color: MyColor.c_28A3ED,
  86. ),
  87. tabs: tabTextList.map((text) => Tab(text: text)).toList(),
  88. ),
  89. );
  90. }
  91. Widget buildPage() {
  92. return PageView.builder(
  93. controller: pageCtrl,
  94. // physics: const BouncingScrollPhysics(),
  95. onPageChanged: (index) {
  96. if (index == tabCtrl.index) return;
  97. tabCtrl.animateTo(index);
  98. },
  99. itemCount: pageList.length,
  100. itemBuilder: (_, index) => pageList[index],
  101. );
  102. }
  103. }