2017-10-20 184 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 :) –