Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`vsync` property in TabController constructor

According to this: sample code

I created my own implementation of 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(),         ),       ),     );   } } 

In line: _tabController = new TabController(vsync: this, length: choices.length); I got error this message:

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

What is wrong with my code?

like image 875
Kamil Harasimowicz Avatar asked Oct 20 '17 14:10

Kamil Harasimowicz


People also ask

What is vsync in TabController flutter?

vsync takes a TickerProvider as an argument , that's why we use SingleTickerProviderStateMixin and as the named describes TickerProvider provides Ticker which simply means it tells our app about the Frame update(or Screen Update), so that our AnimationController can generate a new value and we can redraw the animated ...

What is TabController in flutter?

TabController class Null safety. Coordinates tab selection between a TabBar and a TabBarView. The index property is the index of the selected tab and the animation represents the current scroll positions of the tab bar and the tab bar view. The selected tab's index can be changed with animateTo.


1 Answers

Add with TickerProviderStateMixin to the end of your State’s class declaration.

like image 99
Collin Jackson Avatar answered Sep 22 '22 07:09

Collin Jackson