123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import 'package:flutter/material.dart';
- import 'package:lszlgl/base/base_state.dart';
- import 'package:lszlgl/config/colors.dart';
- import 'package:lszlgl/page/reap_step/reap_step_list_page.dart';
- enum StepType {
- reap(title: '收获环节'),
- stock(title: '库存环节');
- const StepType({required this.title});
- final String title;
- }
- class ReapStepTabPageArgs {
- final StepType type;
- const ReapStepTabPageArgs({required this.type});
- }
- /// 收获环节
- class ReapStepTabPage extends StatefulWidget {
- final ReapStepTabPageArgs args;
- const ReapStepTabPage({
- Key? key,
- ReapStepTabPageArgs? args,
- }) : args = args ?? const ReapStepTabPageArgs(type: StepType.reap),
- super(key: key);
- @override
- State<ReapStepTabPage> createState() => _ReapStepTabPageState();
- }
- class _ReapStepTabPageState extends BaseState<ReapStepTabPage> with TickerProviderStateMixin {
- late TabController tabCtrl;
- late PageController pageCtrl;
- late List<String> tabTextList;
- late List<Widget> pageList;
- @override
- void initState() {
- super.initState();
- tabCtrl = TabController(length: 2, vsync: this);
- pageCtrl = PageController();
- tabTextList = ['待扦样', '扦样完成'];
- pageList = [
- ReapStepListPage(type: widget.args.type),
- ReapStepListPage(type: widget.args.type, complete: true),
- ];
- }
- @override
- Widget build(BuildContext context) {
- return myScaffold(child: buildBody());
- }
- Widget buildBody() {
- return Column(
- children: [
- myAppBar(title: widget.args.type.title),
- buildTab(),
- const SizedBox(height: 12),
- Expanded(child: buildPage()),
- ],
- );
- }
- Widget buildTab() {
- return Container(
- clipBehavior: Clip.hardEdge,
- height: 36,
- decoration: const BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(100)),
- border: Border.fromBorderSide(BorderSide(color: Colors.white, width: 1)),
- ),
- child: TabBar(
- controller: tabCtrl,
- onTap: (index) {
- if ((pageCtrl.page?.toInt() ?? 0) == index) return;
- pageCtrl.animateToPage(index, duration: const Duration(milliseconds: 200), curve: Curves.ease);
- },
- tabAlignment: TabAlignment.center,
- indicator: const BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(100)),
- color: MyColor.c_28A3ED,
- ),
- indicatorSize: TabBarIndicatorSize.tab,
- dividerHeight: 0,
- labelStyle: const TextStyle(
- fontSize: 14,
- fontWeight: FontWeight.w500,
- color: Colors.white,
- ),
- unselectedLabelStyle: const TextStyle(
- fontSize: 14,
- color: MyColor.c_28A3ED,
- ),
- tabs: tabTextList.map((text) => Tab(text: text)).toList(),
- ),
- );
- }
- Widget buildPage() {
- return PageView.builder(
- controller: pageCtrl,
- // physics: const BouncingScrollPhysics(),
- onPageChanged: (index) {
- if (index == tabCtrl.index) return;
- tabCtrl.animateTo(index);
- },
- itemCount: pageList.length,
- itemBuilder: (_, index) => pageList[index],
- );
- }
- }
|