2017-10-20 175 views
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)

我的代碼有什麼問題?

回答

1

with TickerProviderStateMixin添加到State的類聲明末尾。

+0

就是這樣。現在我在變更標籤期間奇怪的登錄控制檯:'另一個異常被拋出:'package:flutter/src/rendering/object.dart':失敗斷言:第2257行pos 12:'fragment is _InterestingSemanticsFragment':is not true.' –

+0

聽起來沒有關係,也許重新啓動應用/升級你的Flutter? –

+0

好吧,一切正常,tnx :) –