我对Flutter和Dart有点陌生,而Google无法解决这个问题。
说我有这个:class _MapPageState extends BaseState<MapPage> with SingleTickerProviderStateMixin
我想在此之上添加另一个mixin(BasePage),其中包含可重复使用的应用程序栏,抽屉等。布局在this article中进行了描述。
我知道这是不可能的,并且我的IDE抛出一个错误,告诉我将其集成,但是我不知道该怎么做。有解决方案吗?我需要SingleTickerProviderStateMixin
,因为我正在使用的AnimationController需要它。
如果需要,这是自定义mixin代码:
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();
}
最佳答案
事实证明,我当时想的太大了,可以通过简单的逗号来组合mixins。... with SingleTickProviderMixin, BasePageMixin
关于flutter - SingleTickerProviderStateMixin和自定义混合,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62077591/