2017-10-20 33 views
0

Selon ceci: sample code`propriété vsync` dans le constructeur TabController

J'ai créé ma propre implémentation de 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(), 
     ), 
    ), 
    ); 
    } 
} 

En ligne: _tabController = new TabController(vsync: this, length: choices.length); Je suis erreur ce 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)

Quel est le problème avec mon code?

Répondre

1

Ajoutez with TickerProviderStateMixin à la fin de la déclaration de classe de votre State.

+0

C'était ça. Maintenant, je reçois une console de connexion bizarre lors de la modification des onglets: 'Une autre exception a été levée: 'paquet: flutter/src/rendu/object.dart': Assertion échouée: ligne 2257 pos 12: 'fragment est _InterestingSemanticsFragment': non vrai. –

+0

Ne semble pas lié, peut-être redémarrer l'application/mettre à jour votre Flutter? –

+0

ok, tout fonctionne, tnx :) –