Redux (wip)

This commit is contained in:
vjrj 2018-06-27 12:08:36 +02:00
parent 445c9c06cd
commit 866e776389
13 changed files with 150 additions and 7 deletions

View file

@ -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 {

View file

@ -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 }

View file

@ -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;

View file

@ -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;

59
lib/models/appState.dart Normal file
View file

@ -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<YourLocation> yourLocations;
@JsonKey(ignore: true)
final FireMapState fireMapState;
@JsonKey(ignore: true)
factory AppState.fromJson(Map<String, dynamic> 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<YourLocation> 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}';
}
}

View file

@ -0,0 +1,46 @@
// Copyright (c) 2018, Comunes Association.
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'appState.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
AppState _$AppStateFromJson(Map<String, dynamic> json) => new AppState(
yourLocations: (json['yourLocations'] as List)
.map((e) => new YourLocation.fromJson(e as Map<String, dynamic>))
.toList(),
userId: json['userId'] as String,
token: json['token'] as String);
abstract class _$AppStateSerializerMixin {
String get userId;
String get token;
List<YourLocation> get yourLocations;
Map<String, dynamic> toJson() => new _$AppStateJsonMapWrapper(this);
}
class _$AppStateJsonMapWrapper extends $JsonMapWrapper {
final _$AppStateSerializerMixin _v;
_$AppStateJsonMapWrapper(this._v);
@override
Iterable<String> 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;
}
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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';

View file

@ -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.