MainDrawer singleton

This commit is contained in:
Vicente J. Ruiz Jurado 2018-08-03 20:24:26 +02:00
parent 4e50f5e8f7
commit eeee50d09b
4 changed files with 17 additions and 4 deletions

View file

@ -203,7 +203,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
// FIXME new? // FIXME new?
drawer: new MainDrawer(context), drawer: MainDrawer.getDrawer(context),
appBar: new AppBar( appBar: new AppBar(
title: Text(title), title: Text(title),
leading: IconButton( leading: IconButton(

View file

@ -178,7 +178,7 @@ class _FireNotificationListState extends State<FireNotificationList> {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
drawer: new MainDrawer(context), drawer: MainDrawer.getDrawer(context),
appBar: new AppBar( appBar: new AppBar(
title: Text(title), title: Text(title),
leading: IconButton( leading: IconButton(

View file

@ -27,7 +27,7 @@ class HomePage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
drawer: new MainDrawer(context), drawer: MainDrawer.getDrawer(context),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: floatingActionButton:
Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[

View file

@ -2,6 +2,7 @@ import 'package:badge/badge.dart';
import 'package:comunes_flutter/comunes_flutter.dart'; import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'activeFires.dart'; import 'activeFires.dart';
import 'colors.dart'; import 'colors.dart';
@ -37,6 +38,18 @@ class _ViewModel {
class MainDrawer extends Drawer { class MainDrawer extends Drawer {
MainDrawer(BuildContext context, {key}) MainDrawer(BuildContext context, {key})
: super(key: key, child: mainDrawer(context)); : 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) { Widget mainDrawer(BuildContext context) {
@ -97,7 +110,7 @@ Widget mainDrawer(BuildContext context) {
leading: const Icon(Icons.notifications), leading: const Icon(Icons.notifications),
title: view.unreadCount > 0 title: view.unreadCount > 0
? Badge.after( ? Badge.after(
spacing: 5.0, spacing: 5.0,
borderColor: Colors.red, borderColor: Colors.red,
child: Text(S.of(context).fireNotificationsTitleShort), child: Text(S.of(context).fireNotificationsTitleShort),
value: ' ${view.unreadCount.toString()} ') value: ' ${view.unreadCount.toString()} ')