MainDrawer singleton
This commit is contained in:
parent
4e50f5e8f7
commit
eeee50d09b
4 changed files with 17 additions and 4 deletions
|
|
@ -203,7 +203,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
// FIXME new?
|
||||
drawer: new MainDrawer(context),
|
||||
drawer: MainDrawer.getDrawer(context),
|
||||
appBar: new AppBar(
|
||||
title: Text(title),
|
||||
leading: IconButton(
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
|||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
drawer: new MainDrawer(context),
|
||||
drawer: MainDrawer.getDrawer(context),
|
||||
appBar: new AppBar(
|
||||
title: Text(title),
|
||||
leading: IconButton(
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class HomePage extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
key: _scaffoldKey,
|
||||
drawer: new MainDrawer(context),
|
||||
drawer: MainDrawer.getDrawer(context),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
floatingActionButton:
|
||||
Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:badge/badge.dart';
|
|||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||
|
||||
import 'activeFires.dart';
|
||||
import 'colors.dart';
|
||||
|
|
@ -37,6 +38,18 @@ class _ViewModel {
|
|||
class MainDrawer extends Drawer {
|
||||
MainDrawer(BuildContext context, {key})
|
||||
: super(key: key, child: mainDrawer(context));
|
||||
|
||||
static getDrawer(BuildContext context) {
|
||||
Injector inj = Injector.getInjector();
|
||||
MainDrawer d;
|
||||
try {
|
||||
d = inj.get<MainDrawer>();
|
||||
} catch (e) {
|
||||
inj.map<MainDrawer>((i) => new MainDrawer(context), isSingleton: true);
|
||||
d = inj.get<MainDrawer>();
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
Widget mainDrawer(BuildContext context) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue