diff --git a/lib/activeFires.dart b/lib/activeFires.dart index ea1e3c8..3605257 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -12,7 +12,7 @@ import 'globals.dart' as globals; import 'locationUtils.dart'; import 'mainDrawer.dart'; import 'placesAutocompleteUtils.dart'; -import 'yourLocation.dart'; +import 'package:fires_flutter/models/yourLocation.dart'; import 'yourLocationPersist.dart'; class ActiveFiresPage extends StatefulWidget { diff --git a/lib/genericMap.dart b/lib/genericMap.dart index 644b4e7..da99af8 100644 --- a/lib/genericMap.dart +++ b/lib/genericMap.dart @@ -10,7 +10,7 @@ import 'package:http/http.dart' as http; import 'package:just_debounce_it/just_debounce_it.dart'; import 'package:latlong/latlong.dart'; -import 'basicLocation.dart'; +import 'package:fires_flutter/models/basicLocation.dart'; import 'colors.dart'; import 'customBottomAppBar.dart'; import 'dummyMapPlugin.dart'; @@ -19,7 +19,7 @@ import 'fireMarker.dart'; import 'generated/i18n.dart'; import 'globals.dart' as globals; import 'slider.dart'; -import 'yourLocation.dart'; +import 'package:fires_flutter/models/yourLocation.dart'; import 'zoomMapPlugin.dart'; enum MapOperation { view, subscriptionConfirm, unsubscribe } diff --git a/lib/globals.dart b/lib/globals.dart index 8cd3edd..1091d6a 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -5,7 +5,7 @@ import 'package:get_it/get_it.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'dart:async'; -import 'yourLocation.dart'; +import 'package:fires_flutter/models/yourLocation.dart'; String gmapKey; String firesApiKey; diff --git a/lib/locationUtils.dart b/lib/locationUtils.dart index e2b41da..14e3a54 100644 --- a/lib/locationUtils.dart +++ b/lib/locationUtils.dart @@ -1,7 +1,7 @@ import 'package:location/location.dart'; import 'package:flutter/services.dart'; import 'dart:async'; -import 'yourLocation.dart'; +import 'package:fires_flutter/models/yourLocation.dart'; import 'package:flutter/material.dart'; import 'package:geocoder/geocoder.dart'; import 'globals.dart' as globals; diff --git a/lib/models/appState.dart b/lib/models/appState.dart new file mode 100644 index 0000000..b46b3fd --- /dev/null +++ b/lib/models/appState.dart @@ -0,0 +1,59 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; + +import 'fireMapState.dart'; +import 'yourLocation.dart'; + +part 'appState.g.dart'; + +@immutable +@JsonSerializable(nullable: false) +class AppState extends Object with _$AppStateSerializerMixin { + @JsonKey(ignore: true) + final bool isLoading; + @JsonKey(ignore: true) + final bool isLoaded; + @JsonKey(ignore: true) + final String error; + final String userId; + final String token; + final List yourLocations; + @JsonKey(ignore: true) + final FireMapState fireMapState; + + @JsonKey(ignore: true) + factory AppState.fromJson(Map json) => + _$AppStateFromJson(json); + + AppState( + {this.yourLocations = const [], + this.userId, + this.token, + this.isLoading: false, + this.isLoaded: false, + this.error: null, + this.fireMapState: const FireMapState.initial()}); + + AppState copyWith( + {bool isLoading, + bool isLoaded, + String userId, + String token, + String error, + List yourLocations, + FireMapState fireMapState}) { + return new AppState( + isLoading: isLoading ?? this.isLoading, + isLoaded: isLoaded ?? this.isLoaded, + userId: userId ?? this.userId, + token: token ?? this.token, + error: error ?? this.error, + yourLocations: yourLocations ?? this.yourLocations, + fireMapState: fireMapState ?? this.fireMapState); + } + + @override + String toString() { + return 'AppState{\nuserId: $userId\ntoken: $token\nisLoading: $isLoading\nisLoaded: $isLoaded\nYourLocations: $yourLocations}'; + } +} diff --git a/lib/models/appState.g.dart b/lib/models/appState.g.dart new file mode 100644 index 0000000..8f4679d --- /dev/null +++ b/lib/models/appState.g.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2018, Comunes Association. + +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'appState.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AppState _$AppStateFromJson(Map json) => new AppState( + yourLocations: (json['yourLocations'] as List) + .map((e) => new YourLocation.fromJson(e as Map)) + .toList(), + userId: json['userId'] as String, + token: json['token'] as String); + +abstract class _$AppStateSerializerMixin { + String get userId; + String get token; + List get yourLocations; + Map toJson() => new _$AppStateJsonMapWrapper(this); +} + +class _$AppStateJsonMapWrapper extends $JsonMapWrapper { + final _$AppStateSerializerMixin _v; + _$AppStateJsonMapWrapper(this._v); + + @override + Iterable get keys => const ['userId', 'token', 'yourLocations']; + + @override + dynamic operator [](Object key) { + if (key is String) { + switch (key) { + case 'userId': + return _v.userId; + case 'token': + return _v.token; + case 'yourLocations': + return _v.yourLocations; + } + } + return null; + } +} diff --git a/lib/basicLocation.dart b/lib/models/basicLocation.dart similarity index 100% rename from lib/basicLocation.dart rename to lib/models/basicLocation.dart diff --git a/lib/models/fireMapState.dart b/lib/models/fireMapState.dart new file mode 100644 index 0000000..c32b8ee --- /dev/null +++ b/lib/models/fireMapState.dart @@ -0,0 +1,27 @@ +import 'package:meta/meta.dart'; + +enum FireMapOperation { view, subscriptionConfirm, unsubscribe } + +@immutable +class FireMapState { + final FireMapOperation currentOperation; + + const FireMapState.initial(): this.currentOperation = FireMapOperation.view; + + FireMapState({this.currentOperation: FireMapOperation.view}); + + @override + bool operator ==(Object other) => + identical(this, other) || + other is FireMapState && + runtimeType == other.runtimeType && + currentOperation == other.currentOperation; + + @override + int get hashCode => currentOperation.hashCode; + + FireMapState copyWith({FireMapOperation currentOperation}) { + return new FireMapState( + currentOperation: currentOperation ?? this.currentOperation); + } +} diff --git a/lib/yourLocation.dart b/lib/models/yourLocation.dart similarity index 100% rename from lib/yourLocation.dart rename to lib/models/yourLocation.dart diff --git a/lib/yourLocation.g.dart b/lib/models/yourLocation.g.dart similarity index 100% rename from lib/yourLocation.g.dart rename to lib/models/yourLocation.g.dart diff --git a/lib/placesAutocompleteUtils.dart b/lib/placesAutocompleteUtils.dart index 7cc8c52..bf66e52 100644 --- a/lib/placesAutocompleteUtils.dart +++ b/lib/placesAutocompleteUtils.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_google_places_autocomplete/flutter_google_places_autocomplete.dart'; -import 'yourLocation.dart'; +import 'package:fires_flutter/models/yourLocation.dart'; import 'generated/i18n.dart'; import 'globals.dart' as globals; diff --git a/lib/yourLocationPersist.dart b/lib/yourLocationPersist.dart index 5e1a69e..4fb37fb 100644 --- a/lib/yourLocationPersist.dart +++ b/lib/yourLocationPersist.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'yourLocation.dart'; +import 'package:fires_flutter/models/yourLocation.dart'; import 'globals.dart' as globals; import 'package:shared_preferences/shared_preferences.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 6b21e26..ed828c4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,9 +14,11 @@ dependencies: # utils simple_moment: "^0.0.3" just_debounce_it: "^1.0.4" + # net http: "^0.11.3+16" jaguar_resty: "^2.5.5" + # data json_annotation: ^0.2.3 shared_preferences: "^0.4.2" @@ -24,18 +26,27 @@ dependencies: comunes_flutter: path: /home/vjrj/dev/comunes_flutter version: "^0.0.10" + + # redux + redux: "^3.0.0" + flutter_redux: "^0.5.2" + redux_logging: "^0.3.0" + # maps, geo, etc flutter_map: "^0.0.1" flutter_google_places_autocomplete: "^0.0.4" location: "^1.3.4" geocoder: "^0.0.1" + # layout fluttery: "^0.0.7" # https://pub.dartlang.org/packages/padder padder: "^1.0.1" flutter_fab_dialer: "^0.0.5" + # firebase firebase_messaging: "^1.0.2" + # icons # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.