flutter tab页面切换练手,手势滑动、禁止滑动、page切换动画,禁止切换动画。

1:AppBar、TabBar、TabBarView实现页面切换,点击tab后tabBarView有左右切换动画,滑动page联动tabBar

class DevicePage extends StatefulWidget {
  const DevicePage({super.key});

  @override
  State<DevicePage> createState() => _DeviceState();
}

class _DeviceState extends State<DevicePage>
    with SingleTickerProviderStateMixin {
  TabController? _tabController;

  List<Tab> tabs = [
    const Tab(
      text: '设备类型',
    ),
    const Tab(
      text: '设备规格',
    ),
    const Tab(
      text: '设备台账',
    ),
  ];
  int _cuttentIndex = 0;
  List<Widget> tabViews = [
    const TabDeviceType(),
    const TabDeviceSpecs(),
    const TabDeviceLedger()
  ];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        backgroundColor: AppColors.baseColor,
        centerTitle: true,
        title: TabBar(
          controller: _tabController,
          tabs: tabs,
          isScrollable: false,
          labelStyle: TextStyle(
              color: Colors.white,
              fontSize: 16.sp,
              fontWeight: FontWeight.bold),
          unselectedLabelStyle: TextStyle(
              color: const Color(0x99FFFFFF),
              fontSize: 15.sp,
              fontWeight: FontWeight.normal),
          indicatorColor: Colors.white,
          dividerHeight: 0,
          indicatorPadding: EdgeInsets.only(top: 3.h),
          indicator:
              MyCustomIndicator(indWidth: 13.w, indHeight: 3.w, radius: 2.w),
          // onTap:(int index){   针对点击tab page无切换动画
          //   _cuttentIndex = index;
          //   print('index = $index');
          //   setState(() {}); //刷新状态
          // },
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: tabViews,
        // physics: new NeverScrollableScrollPhysics(),  //禁止页面左右手势滑动
      ),
      // body: tabViews[_cuttentIndex],
    );
  }
}

2:只tab点击切换,带page切换动画,关闭page手势切换。

3:关闭Tab点击切换动画

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-26 11:04:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-26 11:04:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-26 11:04:05       87 阅读
  4. Python语言-面向对象

    2024-01-26 11:04:05       96 阅读

热门阅读

  1. 【MQ01】什么是消息队列?用哪个消息队列?

    2024-01-26 11:04:05       47 阅读
  2. 实习记录——第四天

    2024-01-26 11:04:05       48 阅读
  3. webpack tree shaking 摇树原理

    2024-01-26 11:04:05       43 阅读
  4. 数据结构进阶:二叉搜索树

    2024-01-26 11:04:05       57 阅读
  5. XGBoost系列8——XGBoost的未来:从强化学习到AutoML

    2024-01-26 11:04:05       57 阅读
  6. Android 通知栏使用总结

    2024-01-26 11:04:05       57 阅读
  7. IPQ5018: Low-Cost OFDMA Supported WiFi 6 IIoT Solution DR5018

    2024-01-26 11:04:05       51 阅读