Roh*_*han 2 mixins dart flutter
我是 Flutter 和 Dart 的新手,Google 无法帮助我解决这个问题。
假设我有这个:
class _MapPageState extends BaseState<MapPage> with SingleTickerProviderStateMixin
我想在此之上添加另一个 mixin (BasePage),其中包含可重用的应用程序栏、抽屉等。本文介绍了布局。
我知道这是不可能的,我的 IDE 会抛出一个错误,告诉我集成它们,但我不知道如何集成。有解决办法吗?我需要SingleTickerProviderStateMixin
,因为我正在使用的动画控制器需要它。
如果需要的话,这是自定义 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();
}
Run Code Online (Sandbox Code Playgroud)