SingleTickerProviderStateMixin和自定义混合

问题描述 投票:0回答:1

我对Flutter和Dart有点陌生,而Google无法解决这个问题。

说我有这个:

class _MapPageState extends BaseState<MapPage> with SingleTickerProviderStateMixin

我想在此之上添加另一个mixin(BasePage),其中包含可重复使用的应用栏,抽屉等。布局在this article中进行了描述。

我知道这是不可能的,并且我的IDE引发错误,告诉我将它们集成,但是我不知道如何。有解决方案吗?我需要SingleTickerProviderStateMixin,因为我正在使用的AnimationController需要它。

这里是自定义混合代码,如果需要:

abstract class Base extends StatefulWidget {
  Base({Key key}) : super(key: key);
}

abstract class BaseState<Page extends Base> extends State<Page> {
  String screenName();
}

mixin BasePage<Page extends Base> on BaseState<Page> {

  MapFunctions functions = MapFunctions();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Guidey'),
          backgroundColor: Colors.deepOrangeAccent,
          centerTitle: true,
        ),
        drawer: Theme(
          data: Theme.of(context).copyWith(
            canvasColor: Colors.black.withOpacity(0.5)
          ),
          child: Drawer(
            child: ListView(
              padding: EdgeInsets.fromLTRB(40.0, 10.0, 40.0, 10.0),
              children: <Widget>[
                DrawerHeader(
                  child: Padding(
                    padding: EdgeInsets.fromLTRB(0, 35, 0, 0),
                    child: Text('Navigation', textAlign: TextAlign.center, style: TextStyle(fontSize: 20, color: Colors.white))
                  )
                ),
                ListTile(
                  title: Text('Profile', style: TextStyle(color: Colors.white)),
                  trailing: Icon(Icons.account_circle, color: Colors.white70),
                  onTap: (){
                    Navigator.of(context).pop();
                  },
                ),
                ListTile(
                  title: Text('Map', style: TextStyle(color: Colors.white)),
                  trailing: Icon(Icons.drive_eta, color: Colors.white70),
                  onTap: (){
                    Navigator.of(context).pop();
                  },
                ),
                ListTile(
                  title: Text('My Location', style: TextStyle(color: Colors.white)),
                  trailing: Icon(Icons.store, color: Colors.white70),
                  onTap: (){
                  },
                )
              ],
            )
          ),
        ),
    );
  }

  Widget body();
}
flutter dart mixins
1个回答
0
投票

事实证明,我当时想的太大了,可以通过简单的逗号来组合mixins。

... with SingleTickProviderMixin, BasePageMixin

© www.soinside.com 2019 - 2024. All rights reserved.