gpt4 book ai didi

dart - TabController 构造函数中的 `vsync` 属性

转载 作者:IT老高 更新时间:2023-10-28 12:30:16 27 4
gpt4 key购买 nike

据此:sample code

我创建了自己的 TabController 实现:

void main() {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {

@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

TabController _tabController;

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

@override
void dispose() {
_tabController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
bottomNavigationBar: new Material(
color: Colors.blue,
child: new TabBar(
controller: _tabController,
isScrollable: false,
tabs: choices.map((Choice choice) {
return new Tab(
text: null,
icon: new Icon(choice.icon),
);
}).toList(),
),
),
appBar: new AppBar(
title: const Text('Swap'),
),
body: new TabBarView(
controller: _tabController,
children: choices.map((Choice choice) {
return new Padding(
padding: const EdgeInsets.all(16.0),
child: new ChoiceCard(choice: choice),
);
}).toList(),
),
),
);
}
}

行内:_tabController = new TabController(vsync: this, length:choices.length); 我收到错误消息:

error: The argument type '_MyAppState' can't be assigned to the parameter type 'TickerProvider'. (argument_type_not_assignable at [swap] lib/main.dart:24)

我的代码有什么问题?

最佳答案

with TickerProviderStateMixin 添加到 State 的类声明的末尾。

关于dart - TabController 构造函数中的 `vsync` 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46851245/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com