Markdown. Privacy Policies. Injection dep updated
This commit is contained in:
parent
8301e6a40e
commit
f0ab472b3a
21 changed files with 487 additions and 25 deletions
32
lib/fileUtils.dart
Normal file
32
lib/fileUtils.dart
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import 'dart:async';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final esRegExp = new RegExp("^es-");
|
||||
|
||||
String getFallbackLang(String lang) {
|
||||
if (lang == 'ast' || lang == 'gl' || lang == 'eu' ||
|
||||
lang == 'es' || lang == 'ca' || (esRegExp).allMatches(lang).length > 0) {
|
||||
return 'es';
|
||||
}
|
||||
return 'en';
|
||||
}
|
||||
|
||||
Future<String> getFileNameOfLang({@required String dir,@required String fileName,@required String ext,@required String lang}) async {
|
||||
String base = '$dir/$fileName';
|
||||
String fallback = getFallbackLang(lang);
|
||||
String file = '${base}-${lang}.${ext}';
|
||||
if (await assetNotExists(file)) {
|
||||
file = '${base}-${fallback}.${ext}';
|
||||
if (await assetNotExists(file)) {
|
||||
file = '${base}.${ext}';
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
// https://github.com/flutter/flutter/issues/15325
|
||||
Future<bool> assetNotExists(String asset) {
|
||||
print('Does not exists $asset ?');
|
||||
return rootBundle.load(asset).then((_) => false).catchError((err, stack) { print (err); print(stack); return true;});
|
||||
}
|
||||
|
|
@ -6,17 +6,16 @@ import 'fireMarkerIcon.dart';
|
|||
import 'fireMarkType.dart';
|
||||
|
||||
class FireMarker extends Marker {
|
||||
|
||||
FireMarker(location, type,
|
||||
[AnchorPos anchor = AnchorPos.center, Anchor anchorOverride])
|
||||
[onTap = null, AnchorPos anchor = AnchorPos.center, Anchor anchorOverride])
|
||||
: super(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
point: new LatLng(location.lat, location.lon),
|
||||
builder: (ctx) => new Container(
|
||||
child: new GestureDetector(
|
||||
child: new FireMarkerIcon(type), onTap: () {
|
||||
print('marker pressed');
|
||||
})
|
||||
child: new FireMarkerIcon(type), onTap: onTap)
|
||||
),
|
||||
anchor: anchor,
|
||||
anchorOverride: anchorOverride ?? type == FireMarkType.position
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import 'models/appState.dart';
|
|||
import 'redux/actions.dart';
|
||||
import 'sandbox.dart';
|
||||
import 'theme.dart';
|
||||
import 'privacyPage.dart';
|
||||
|
||||
class FiresApp extends StatelessWidget {
|
||||
static final WidgetBuilder introWidget = (context) => new IntroPage();
|
||||
|
|
@ -20,6 +21,7 @@ class FiresApp extends StatelessWidget {
|
|||
final Map routes = <String, WidgetBuilder>{
|
||||
IntroPage.routeName: introWidget,
|
||||
HomePage.routeName: continueWidget,
|
||||
PrivacyPage.routeName: (BuildContext context) => new PrivacyPage(context),
|
||||
ActiveFiresPage.routeName: (BuildContext context) => new ActiveFiresPage(),
|
||||
Sandbox.routeName: (BuildContext context) => new Sandbox(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class S implements WidgetsLocalizations {
|
|||
String get isYourUbicationEnabled => "I cannot get your current location. It's your ubication enabled?";
|
||||
String get notPermsUbication => "We don't have permission to get your location";
|
||||
String get notifyAFire => "Notify a fire";
|
||||
String get privacyPolicy => "Privacy Policy";
|
||||
String get supportThisInitiative => "Support this initiative";
|
||||
String get toDeleteThisPlace => "Slide horizontally to delete this place";
|
||||
String get toFiresNotifications => "Subscribe to fires notifications";
|
||||
|
|
@ -120,6 +121,8 @@ class es extends S {
|
|||
@override
|
||||
String get aF3wSeconds => "unos segundos";
|
||||
@override
|
||||
String get privacyPolicy => "Política de Privacidad";
|
||||
@override
|
||||
String get activeFires => "Fuegos activos";
|
||||
@override
|
||||
String get aMonth => "un mes";
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class GlobalFiresBottomStats extends StatefulWidget {
|
|||
class _GlobalFiresBottomStatsState extends State<GlobalFiresBottomStats> {
|
||||
String lastCheck;
|
||||
int activeFires = 0;
|
||||
final firesApiUrl = Injector.getInjector().get(String, "firesApiUrl");
|
||||
final firesApiUrl = Injector.getInjector().get<String>(key: "firesApiUrl");
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ Future<YourLocation> getUserLocation(
|
|||
Future<String> getReverseLocation(YourLocation loc,
|
||||
[bool external = false]) async {
|
||||
final coordinates = new Coordinates(loc.lat, loc.lon);
|
||||
var geoCoder = external ? Geocoder.google(Injector.getInjector().get(String, "gmapKey")) : Geocoder.local;
|
||||
var geoCoder = external ? Geocoder.google(Injector.getInjector().get<String>(key: "gmapKey")) : Geocoder.local;
|
||||
var addresses = await geoCoder.findAddressesFromCoordinates(coordinates);
|
||||
var first = addresses.first;
|
||||
print("${first.featureName} : ${first.addressLine}");
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ Future<Map<String, dynamic>> loadSecrets() async {
|
|||
|
||||
void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
||||
final injector = Injector.getInjector();
|
||||
injector.map(FiresApi, (i) => new FiresApi(), isSingleton: true);
|
||||
injector.map<FiresApi>((i) => new FiresApi(), isSingleton: true);
|
||||
loadSecrets().then((secrets) {
|
||||
final store = new Store<AppState>(appStateReducer,
|
||||
initialState: new AppState(
|
||||
|
|
@ -31,9 +31,9 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
|||
middleware: List.from(otherMiddleware)
|
||||
..add(fetchYourLocationsMiddleware));
|
||||
|
||||
injector.map(String, (i) => store.state.firesApiUrl, key: "firesApiUrl");
|
||||
injector.map(String, (i) => store.state.firesApiKey, key: "firesApiKey");
|
||||
injector.map(String, (i) => store.state.gmapKey, key: "gmapKey");
|
||||
injector.map<String>((i) => store.state.firesApiUrl, key: "firesApiUrl");
|
||||
injector.map<String>((i) => store.state.firesApiKey, key: "firesApiKey");
|
||||
injector.map<String>((i) => store.state.gmapKey, key: "gmapKey");
|
||||
|
||||
VoidCallback mainFn = () {
|
||||
loadYourLocations().then((yl) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'activeFires.dart';
|
|||
import 'globals.dart' as globals;
|
||||
import 'generated/i18n.dart';
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'privacyPage.dart';
|
||||
|
||||
class MainDrawer extends Drawer {
|
||||
MainDrawer(BuildContext context, {key})
|
||||
|
|
@ -61,6 +62,15 @@ Widget mainDrawer(BuildContext context) {
|
|||
},
|
||||
),
|
||||
new Divider(),
|
||||
new ListTile(
|
||||
leading: const Icon(Icons.lock),
|
||||
title: new Text(S.of(context).privacyPolicy),
|
||||
onTap: () {
|
||||
// Then close the drawer
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, PrivacyPage.routeName);
|
||||
},
|
||||
),
|
||||
new ListTile(
|
||||
leading: const Icon(Icons.favorite),
|
||||
title: new Text(S.of(context).supportThisInitiative),
|
||||
|
|
|
|||
42
lib/markdownPage.dart
Normal file
42
lib/markdownPage.dart
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
|
||||
import 'globals.dart' as globals;
|
||||
|
||||
abstract class MarkdownPage extends StatefulWidget {
|
||||
final String title;
|
||||
final Future<String> file;
|
||||
|
||||
MarkdownPage({this.title, this.file});
|
||||
|
||||
@override
|
||||
_MarkdownPageState createState() =>
|
||||
_MarkdownPageState(title: this.title, file: this.file);
|
||||
}
|
||||
|
||||
class _MarkdownPageState extends State<MarkdownPage> {
|
||||
final String title;
|
||||
final Future<String> file;
|
||||
String pageData = "";
|
||||
|
||||
_MarkdownPageState({this.title, this.file});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
this.file.then((fileSync) {
|
||||
rootBundle
|
||||
.loadString(fileSync, cache: !globals.isDevelopment)
|
||||
.then((pageData) {
|
||||
setState(() {
|
||||
this.pageData = pageData;
|
||||
});
|
||||
});
|
||||
});
|
||||
return new Scaffold(
|
||||
appBar: new SliverAppBar(title: new Text(title ?? '')),
|
||||
body: new Markdown(data: pageData));
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import 'package:flutter_simple_dependency_injection/injector.dart';
|
|||
|
||||
Future<YourLocation> openPlacesDialog(GlobalKey<ScaffoldState> sc) async {
|
||||
Mode _mode = Mode.overlay;
|
||||
String gmapKey = Injector.getInjector().get(String, "gmapKey");
|
||||
String gmapKey = Injector.getInjector().get<String>(key: "gmapKey");
|
||||
GoogleMapsPlaces _places = new GoogleMapsPlaces(gmapKey);
|
||||
Prediction p = await showGooglePlacesAutocomplete(
|
||||
context: sc.currentContext,
|
||||
|
|
|
|||
18
lib/privacyPage.dart
Normal file
18
lib/privacyPage.dart
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'fileUtils.dart';
|
||||
import 'generated/i18n.dart';
|
||||
import 'markdownPage.dart';
|
||||
|
||||
class PrivacyPage extends MarkdownPage {
|
||||
static const String routeName = '/privacy';
|
||||
|
||||
PrivacyPage(context)
|
||||
: super(
|
||||
title: S.of(context).privacyPolicy,
|
||||
file: getFileNameOfLang(
|
||||
dir: 'assets/pages',
|
||||
fileName: 'privacy',
|
||||
ext: 'md',
|
||||
lang: Localizations.localeOf(context).languageCode));
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ import 'actions.dart';
|
|||
// Middleware do not return any values themselves. They simply forward
|
||||
// actions on to the Reducer or swallow actions in some special cases.
|
||||
|
||||
FiresApi api = Injector.getInjector().get<FiresApi>(FiresApi);
|
||||
FiresApi api = Injector.getInjector().get<FiresApi>();
|
||||
|
||||
void fetchYourLocationsMiddleware(
|
||||
Store<AppState> store, action, NextDispatcher next) {
|
||||
|
|
|
|||
|
|
@ -13,14 +13,28 @@ class Sandbox extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
//showDialog(context: context, child: builder(context));
|
||||
return Scaffold(
|
||||
appBar: new AppBar(
|
||||
title: new TextField(
|
||||
autofocus: true,
|
||||
controller: new TextEditingController(text: "kk"),
|
||||
decoration: new InputDecoration(),
|
||||
onSubmitted: (todoText) {},
|
||||
)),
|
||||
body: new Text("Sandbox"),
|
||||
);
|
||||
appBar: new AppBar(
|
||||
title: new TextField(
|
||||
autofocus: true,
|
||||
controller: new TextEditingController(text: "kk"),
|
||||
decoration: new InputDecoration(),
|
||||
onSubmitted: (todoText) {},
|
||||
)),
|
||||
body: new RaisedButton(
|
||||
child: new Text('Press'),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return new SimpleDialog(
|
||||
title: new Text('title'),
|
||||
children: <Widget>[
|
||||
new Padding(
|
||||
padding: const EdgeInsets.only(left: 16.0),
|
||||
child: new Text('hhh'),
|
||||
),
|
||||
]);
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ class _YourLocationMapState extends State<YourLocationMap> {
|
|||
});
|
||||
fires.forEach((fire) {
|
||||
var loc = new BasicLocation(lat: fire['lat'], lon: fire['lon']);
|
||||
markers.add(FireMarker(loc, FireMarkType.fire));
|
||||
markers.add(FireMarker(loc, FireMarkType.fire, () => print('marker pressed')));
|
||||
markers.add(FireMarker(loc, FireMarkType.pixel));
|
||||
});
|
||||
return markers;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue