tabs切换
简单的tabs切换
- // view
- Widget _buildTab() {
- return TDTabBar(
- controller: controller.tabController,
- tabs: controller.tabNames.map((e) => TDTab(text: e)).toList(),
- onTap: (index) => controller.onTapTabItem(index),
- backgroundColor: Colors.white,
- showIndicator: true,
- indicatorColor: const Color(0xffe01e1e),
- labelColor: const Color(0xffe01e1e),
- );
- }
- // controller
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- class OrderDetailController extends GetxController with GetTickerProviderStateMixin {
- OrderDetailController();
- // tab 控制器
- late TabController tabController;
- // tab 索引
- int tabIndex = 0;
- // tab 名称
- List<String> tabNames = ['全部', '待付款', '待发货', '待收货', '已完成'];
- void onTapTabItem(int index) {
- tabIndex = index;
- print('tabIndex: $tabIndex');
- update(["order_detail"]);
- }
-
- @override
- void onInit() {
- super.onInit();
- tabController = TabController(length: tabNames.length, vsync: this);
- }
- @override
- void onClose() {
- super.onClose();
- tabController.dispose();
- }
- }
复制代码 tabs切换和视图同步
- // view
- Widget _buildView() {
- return <Widget>[
- _buildTab(),
- Expanded(
- child: TabBarView(
- controller: controller.tabController,
- children: const [
- Center(child: Text('内容1')),
- Center(child: Text('内容2')),
- Center(child: Text('内容3')),
- Center(child: Text('内容4')),
- Center(child: Text('内容5')),
- ],
- ),
- ),
- ].toColumn();
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |