Added simple injector
This commit is contained in:
parent
de340c0664
commit
a9329e3824
8 changed files with 49 additions and 55 deletions
|
|
@ -37,11 +37,10 @@ class _ViewModel {
|
||||||
identical(this, other) ||
|
identical(this, other) ||
|
||||||
other is _ViewModel &&
|
other is _ViewModel &&
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
yourLocations == other.yourLocations ;
|
yourLocations == other.yourLocations;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode =>
|
int get hashCode => yourLocations.hashCode;
|
||||||
yourLocations.hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ActiveFiresPage extends StatelessWidget {
|
class ActiveFiresPage extends StatelessWidget {
|
||||||
|
|
@ -104,36 +103,30 @@ class ActiveFiresPage extends StatelessWidget {
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
itemCount: yl.length,
|
itemCount: yl.length,
|
||||||
itemBuilder: (BuildContext _context, int i) {
|
itemBuilder: (BuildContext _context, int i) {
|
||||||
return _buildItem(
|
|
||||||
context, yl.elementAt(i), onDeleted, onToggle, onTap);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildItem(
|
|
||||||
BuildContext context, YourLocation item, onDelete, onToggle, onTap) {
|
|
||||||
final ThemeData theme = Theme.of(context);
|
final ThemeData theme = Theme.of(context);
|
||||||
return new Dismissible(
|
return new Dismissible(
|
||||||
key: new ObjectKey(item),
|
key: new ObjectKey(yl.elementAt(i)),
|
||||||
direction: DismissDirection.horizontal,
|
direction: DismissDirection.horizontal,
|
||||||
onDismissed: (DismissDirection direction) {
|
onDismissed: (DismissDirection direction) {
|
||||||
onDelete(item);
|
onDeleted(yl.elementAt(i));
|
||||||
},
|
},
|
||||||
background: new Container(
|
background: new Container(
|
||||||
color: theme.primaryColor,
|
color: theme.primaryColor,
|
||||||
child: const ListTile(
|
child: const ListTile(
|
||||||
leading:
|
leading: const Icon(Icons.delete,
|
||||||
const Icon(Icons.delete, color: Colors.white, size: 36.0))),
|
color: Colors.white, size: 36.0))),
|
||||||
secondaryBackground: new Container(
|
secondaryBackground: new Container(
|
||||||
color: theme.primaryColor,
|
color: theme.primaryColor,
|
||||||
child: const ListTile(
|
child: const ListTile(
|
||||||
trailing:
|
trailing: const Icon(Icons.delete,
|
||||||
const Icon(Icons.delete, color: Colors.white, size: 36.0))),
|
color: Colors.white, size: 36.0))),
|
||||||
child: new Container(
|
child: new Container(
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
color: theme.canvasColor,
|
color: theme.canvasColor,
|
||||||
border: new Border(
|
border: new Border(
|
||||||
bottom: new BorderSide(color: theme.dividerColor))),
|
bottom: new BorderSide(color: theme.dividerColor))),
|
||||||
child: _buildRow(context, item, onToggle, onTap)));
|
child: _buildRow(context, yl.elementAt(i), onToggle, onTap)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import 'customBottomAppBar.dart';
|
||||||
import 'colors.dart';
|
import 'colors.dart';
|
||||||
import 'generated/i18n.dart';
|
import 'generated/i18n.dart';
|
||||||
import 'customMoment.dart';
|
import 'customMoment.dart';
|
||||||
|
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||||
|
|
||||||
class GlobalFiresBottomStats extends StatefulWidget {
|
class GlobalFiresBottomStats extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -16,11 +17,12 @@ class GlobalFiresBottomStats extends StatefulWidget {
|
||||||
class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
||||||
String lastCheck;
|
String lastCheck;
|
||||||
int activeFires = 0;
|
int activeFires = 0;
|
||||||
|
final firesApiUrl = Injector.getInjector().get(String, "firesApiUrl");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
http.read('${globals.firesApiUrl}status/last-fire-check').then((result) {
|
http.read('${firesApiUrl}status/last-fire-check').then((result) {
|
||||||
try {
|
try {
|
||||||
var now = Moment.now();
|
var now = Moment.now();
|
||||||
var last = DateTime.parse(json.decode(result)['value']);
|
var last = DateTime.parse(json.decode(result)['value']);
|
||||||
|
|
@ -31,7 +33,7 @@ class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
||||||
print('Cannot get the last fire check');
|
print('Cannot get the last fire check');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
http.read('${globals.firesApiUrl}status/active-fires-count').then((result) {
|
http.read('${firesApiUrl}status/active-fires-count').then((result) {
|
||||||
try {
|
try {
|
||||||
int count = json.decode(result)['total'];
|
int count = json.decode(result)['total'];
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,9 @@
|
||||||
library fires.globals;
|
library fires.globals;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
// FIXME remove this later
|
|
||||||
String gmapKey;
|
|
||||||
String firesApiKey;
|
|
||||||
String firesApiUrl;
|
|
||||||
final String appVersion = '0.0.1';
|
final String appVersion = '0.0.1';
|
||||||
|
|
||||||
final Widget appMediumIcon =
|
final Widget appMediumIcon =
|
||||||
|
|
@ -16,5 +11,4 @@ final Widget appMediumIcon =
|
||||||
final Widget appIcon =
|
final Widget appIcon =
|
||||||
Image.asset('images/logo-200.png', width: 24.0, height: 24.0);
|
Image.asset('images/logo-200.png', width: 24.0, height: 24.0);
|
||||||
final Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
final Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||||
final GetIt getIt = new GetIt();
|
|
||||||
bool isDevelopment = false;
|
bool isDevelopment = false;
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import 'dart:async';
|
||||||
import 'package:fires_flutter/models/yourLocation.dart';
|
import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:geocoder/geocoder.dart';
|
import 'package:geocoder/geocoder.dart';
|
||||||
import 'globals.dart' as globals;
|
|
||||||
import 'generated/i18n.dart';
|
import 'generated/i18n.dart';
|
||||||
|
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||||
|
|
||||||
Future<YourLocation> getUserLocation(
|
Future<YourLocation> getUserLocation(
|
||||||
GlobalKey<ScaffoldState> scaffoldKey) async {
|
GlobalKey<ScaffoldState> scaffoldKey) async {
|
||||||
|
|
@ -47,7 +47,7 @@ Future<YourLocation> getUserLocation(
|
||||||
Future<String> getReverseLocation(YourLocation loc,
|
Future<String> getReverseLocation(YourLocation loc,
|
||||||
[bool external = false]) async {
|
[bool external = false]) async {
|
||||||
final coordinates = new Coordinates(loc.lat, loc.lon);
|
final coordinates = new Coordinates(loc.lat, loc.lon);
|
||||||
var geoCoder = external ? Geocoder.google(globals.gmapKey) : Geocoder.local;
|
var geoCoder = external ? Geocoder.google(Injector.getInjector().get(String, "gmapKey")) : Geocoder.local;
|
||||||
var addresses = await geoCoder.findAddressesFromCoordinates(coordinates);
|
var addresses = await geoCoder.findAddressesFromCoordinates(coordinates);
|
||||||
var first = addresses.first;
|
var first = addresses.first;
|
||||||
print("${first.featureName} : ${first.addressLine}");
|
print("${first.featureName} : ${first.addressLine}");
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,16 @@ import 'models/firesApi.dart';
|
||||||
import 'redux/fetchDataMiddleware.dart';
|
import 'redux/fetchDataMiddleware.dart';
|
||||||
import 'redux/reducers.dart';
|
import 'redux/reducers.dart';
|
||||||
import 'package:fires_flutter/models/yourLocationPersist.dart';
|
import 'package:fires_flutter/models/yourLocationPersist.dart';
|
||||||
|
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||||
|
|
||||||
Future<Map<String, dynamic>> loadSecrets() async {
|
Future<Map<String, dynamic>> loadSecrets() async {
|
||||||
return await SecretLoader(secretPath: 'assets/private-settings.json').load();
|
return await SecretLoader(secretPath: 'assets/private-settings.json').load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
||||||
globals.getIt.registerSingleton<FiresApi>(new FiresApi());
|
|
||||||
|
final injector = Injector.getInjector();
|
||||||
|
injector.map(FiresApi, (i) => new FiresApi(), isSingleton: true);
|
||||||
loadSecrets().then((secrets) {
|
loadSecrets().then((secrets) {
|
||||||
|
|
||||||
final store = new Store<AppState>(appStateReducer,
|
final store = new Store<AppState>(appStateReducer,
|
||||||
|
|
@ -28,10 +31,9 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
||||||
firesApiUrl: secrets['firesApiUrl'] + "api/v1/"),
|
firesApiUrl: secrets['firesApiUrl'] + "api/v1/"),
|
||||||
middleware: List.from(otherMiddleware)..add(fetchYourLocationsMiddleware));
|
middleware: List.from(otherMiddleware)..add(fetchYourLocationsMiddleware));
|
||||||
|
|
||||||
// FIXME remove this later
|
injector.map(String, (i) => store.state.firesApiUrl, key: "firesApiUrl");
|
||||||
globals.firesApiKey = store.state.firesApiKey;
|
injector.map(String, (i) => store.state.firesApiKey, key: "firesApiKey");
|
||||||
globals.firesApiUrl = store.state.firesApiUrl;
|
injector.map(String, (i) => store.state.gmapKey, key: "gmapKey");
|
||||||
globals.gmapKey = store.state.gmapKey;
|
|
||||||
|
|
||||||
globals.prefs.then((prefs) {
|
globals.prefs.then((prefs) {
|
||||||
loadYourLocationsWithPrefs(prefs);
|
loadYourLocationsWithPrefs(prefs);
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,16 @@ import 'package:flutter_google_places_autocomplete/flutter_google_places_autocom
|
||||||
|
|
||||||
import 'package:fires_flutter/models/yourLocation.dart';
|
import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
import 'generated/i18n.dart';
|
import 'generated/i18n.dart';
|
||||||
import 'globals.dart' as globals;
|
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||||
|
|
||||||
Future<YourLocation> openPlacesDialog(GlobalKey<ScaffoldState> sc) async {
|
Future<YourLocation> openPlacesDialog(GlobalKey<ScaffoldState> sc) async {
|
||||||
Mode _mode = Mode.overlay;
|
Mode _mode = Mode.overlay;
|
||||||
GoogleMapsPlaces _places = new GoogleMapsPlaces(globals.gmapKey);
|
String gmapKey = Injector.getInjector().get(String, "gmapKey");
|
||||||
|
GoogleMapsPlaces _places = new GoogleMapsPlaces(gmapKey);
|
||||||
Prediction p = await showGooglePlacesAutocomplete(
|
Prediction p = await showGooglePlacesAutocomplete(
|
||||||
context: sc.currentContext,
|
context: sc.currentContext,
|
||||||
hint: S.of(sc.currentContext).typeTheNameOfAPlace,
|
hint: S.of(sc.currentContext).typeTheNameOfAPlace,
|
||||||
apiKey: globals.gmapKey,
|
apiKey: gmapKey,
|
||||||
onError: (res) {
|
onError: (res) {
|
||||||
sc.currentState
|
sc.currentState
|
||||||
.showSnackBar(new SnackBar(content: new Text(res.errorMessage)));
|
.showSnackBar(new SnackBar(content: new Text(res.errorMessage)));
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import 'package:bson_objectid/bson_objectid.dart';
|
import 'package:bson_objectid/bson_objectid.dart';
|
||||||
import 'package:fires_flutter/models/yourLocation.dart';
|
import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
|
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||||
import 'package:just_debounce_it/just_debounce_it.dart';
|
import 'package:just_debounce_it/just_debounce_it.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
|
|
||||||
import '../globals.dart' as globals;
|
|
||||||
import '../models/appState.dart';
|
import '../models/appState.dart';
|
||||||
import '../models/firesApi.dart';
|
import '../models/firesApi.dart';
|
||||||
import '../models/yourLocationPersist.dart';
|
import '../models/yourLocationPersist.dart';
|
||||||
|
|
@ -18,7 +18,7 @@ import 'actions.dart';
|
||||||
// Middleware do not return any values themselves. They simply forward
|
// Middleware do not return any values themselves. They simply forward
|
||||||
// actions on to the Reducer or swallow actions in some special cases.
|
// actions on to the Reducer or swallow actions in some special cases.
|
||||||
|
|
||||||
FiresApi api = globals.getIt.get<FiresApi>();
|
FiresApi api = Injector.getInjector().get<FiresApi>(FiresApi);
|
||||||
|
|
||||||
void fetchYourLocationsMiddleware(
|
void fetchYourLocationsMiddleware(
|
||||||
Store<AppState> store, action, NextDispatcher next) {
|
Store<AppState> store, action, NextDispatcher next) {
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,12 @@ dependencies:
|
||||||
# utils
|
# utils
|
||||||
simple_moment: "^0.0.3"
|
simple_moment: "^0.0.3"
|
||||||
just_debounce_it: "^1.0.4"
|
just_debounce_it: "^1.0.4"
|
||||||
|
flutter_simple_dependency_injection: "^0.0.2"
|
||||||
|
|
||||||
# net
|
# net
|
||||||
http: "^0.11.3+16"
|
http: "^0.11.3+16"
|
||||||
jaguar_resty: "^2.5.5"
|
jaguar_resty: "^2.5.5"
|
||||||
|
connectivity: "^0.3.1"
|
||||||
|
|
||||||
# data
|
# data
|
||||||
json_annotation: ^0.2.3
|
json_annotation: ^0.2.3
|
||||||
|
|
@ -34,7 +36,7 @@ dependencies:
|
||||||
redux_logging: "^0.3.0"
|
redux_logging: "^0.3.0"
|
||||||
|
|
||||||
# maps, geo, etc
|
# maps, geo, etc
|
||||||
flutter_map: "^0.0.1"
|
flutter_map: "^0.0.10"
|
||||||
flutter_google_places_autocomplete: "^0.0.4"
|
flutter_google_places_autocomplete: "^0.0.4"
|
||||||
location: "^1.3.4"
|
location: "^1.3.4"
|
||||||
geocoder: "^0.0.1"
|
geocoder: "^0.0.1"
|
||||||
|
|
@ -53,11 +55,11 @@ dependencies:
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: "^0.1.2"
|
cupertino_icons: "^0.1.2"
|
||||||
# not using yet
|
# not using yet
|
||||||
get_it: "^1.0.1+1"
|
|
||||||
# community_material_icon: "^0.1.2"
|
# community_material_icon: "^0.1.2"
|
||||||
# url_launcher: "^3.0.2"
|
# url_launcher: "^3.0.2"
|
||||||
# share: "^0.5.2"
|
# share: "^0.5.2"
|
||||||
# connectivity: "^0.3.1"
|
|
||||||
# package_info: "^0.3.2"
|
# package_info: "^0.3.2"
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue