0
vsync`財產按照這個:sample code`在TabController構造
我創造了我自己的實現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)
我的代碼有什麼問題?
就是這樣。現在我在變更標籤期間奇怪的登錄控制檯:'另一個異常被拋出:'package:flutter/src/rendering/object.dart':失敗斷言:第2257行pos 12:'fragment is _InterestingSemanticsFragment':is not true.' –
聽起來沒有關係,也許重新啓動應用/升級你的Flutter? –
好吧,一切正常,tnx :) –