我想在flutter UI中使用TabBarView,现在使用
get
作为状态管理,这是我的UI代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dev_word_controller.dart';
class DevWord extends StatelessWidget {
DevWord({Key key}) : super(key: key);
List tabs = ["çè¯", "已记ä½", "å
¨é¨"];
@override
Widget build(BuildContext context) {
TabController _tabController = TabController( length: tabs.length, vsync: this);
void _handleTabSelection() {
if (_tabController.indexIsChanging) {
switch (_tabController.index) {
case 0:
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Page 1 tapped.'),
duration: Duration(milliseconds: 500),
));
break;
case 1:
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Page 2 tapped.'),
duration: Duration(milliseconds: 500),
));
break;
}
}
}
_tabController.addListener(_handleTabSelection);
return GetBuilder<DevWordController>(
init: DevWordController(),
builder: (controller) {
return DefaultTabController(
length: tabs.length,
child: Scaffold(
appBar: AppBar(
foregroundColor: Colors.red,
bottom:PreferredSize(
preferredSize: Size.fromHeight(1),
child:Material(
color: Colors.green,
child:TabBar(
indicatorColor: Colors.black,
labelColor: Colors.white,
unselectedLabelColor: Colors.yellow,
tabs: tabs.map((e) => Tab(text: e)).toList())))),
body: SafeArea(
child: TabBarView(
children: tabs.map((e) {
return ListView(children: controller.getCurrentRender);
}).toList(),
),
)),
);
});
}
}
这行代码
TabController _tabController = TabController( length: tabs.length, vsync: this);
显示此错误:
The argument type 'DevWord' can't be assigned to the parameter type 'TickerProvider'.
我应该如何初始化TabController,因为我使用的是get,所以我不想在代码中创建另一个状态。