2017-10-20 3 views
0

zu Demnach: sample code`vsync` Eigenschaft in TabController Konstruktor

ich meine eigene Implementierung von 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 Zeile: _tabController = new TabController(vsync: this, length: choices.length); Ich habe Fehler diese Meldung:

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

Was ist falsch an meinem Code?

Antwort

1

Fügen Sie with TickerProviderStateMixin an das Ende Ihrer Klassendeklaration State.

+0

Es war das. Jetzt bekomme ich seltsame Log-in-Konsole während der Änderung Tabs: 'Eine weitere Ausnahme wurde ausgelöst: 'Paket: Flattern/src/rendering/Objekt.dart': Failed Assertion: Zeile 2257 Pos 12: 'Fragment ist _InterestingSemanticsFragment': ist nicht wahr –

+0

Klingt nicht verwandt, vielleicht App neustarten/Upgrade Flutter? –

+0

ok, alles funktioniert, Tnx :) –

Verwandte Themen