Skip to content

Commit

Permalink
#70 use different main files for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
elKei24 authored and RoAnBu committed Dec 13, 2020
1 parent ce798b8 commit a50ac48
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fe_build_ios_task:
image: catalina-flutter
build_script:
- cd frontend
- flutter build ios --release --no-codesign
- flutter build ios --release --no-codesign -t lib/main_prod.dart
iOS_app_artifacts:
path: ./frontend/build/ios/iphoneos/Runner.app

Expand All @@ -56,7 +56,7 @@ fe_build_android_task:
- "FE: test"
build_script:
- cd frontend
- flutter build appbundle
- flutter build appbundle -t lib/main_prod.dart
android_app_artifacts:
path: ./frontend/build/app/outputs/bundle/release/app-release.aab

Expand Down
6 changes: 6 additions & 0 deletions .idea/runConfigurations/Run_Flutter__local_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 26 additions & 7 deletions frontend/lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

import 'home/home_page.dart';
import 'configuration.dart';

class App extends StatelessWidget {
const App({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Digitale Ehrenamtskarte',
theme: ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.light,
visualDensity: VisualDensity.adaptivePlatformDensity),
home: HomePage(title: "Digitale Ehrenamtskarte"));
final config = Configuration.of(context);
final client = ValueNotifier(
GraphQLClient(
cache: InMemoryCache(),
link: Link.from([
HttpLink(
uri: config.graphqlUrl,
)
]),
),
);
final theme = ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.light,
visualDensity: VisualDensity.adaptivePlatformDensity);
return GraphQLProvider(
child: CacheProvider(
child: MaterialApp(
title: 'Digitale Ehrenamtskarte',
theme: theme,
home: HomePage(title: "Digitale Ehrenamtskarte"))),
client: client);
}
}
23 changes: 23 additions & 0 deletions frontend/lib/configuration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/widgets.dart';

class Configuration extends InheritedWidget {
final String mapStyleUrl;
final String graphqlUrl;

const Configuration({
Key key,
@required this.mapStyleUrl,
@required this.graphqlUrl,
@required Widget child,
}) : assert(mapStyleUrl != null),
assert(graphqlUrl != null),
super(key: key, child: child);

@override
bool updateShouldNotify(covariant Configuration oldWidget) =>
mapStyleUrl != oldWidget.mapStyleUrl ||
graphqlUrl != oldWidget.graphqlUrl;

static Configuration of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<Configuration>();
}
20 changes: 0 additions & 20 deletions frontend/lib/main.dart

This file was deleted.

12 changes: 12 additions & 0 deletions frontend/lib/main_local.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:ehrenamtskarte/configuration.dart';
import 'package:flutter/material.dart';

import 'app.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(Configuration(
mapStyleUrl: "https://vector.ehrenamtskarte.app/style.json",
graphqlUrl: "http://10.0.2.2:7000",
child: App()));
}
12 changes: 12 additions & 0 deletions frontend/lib/main_prod.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:ehrenamtskarte/configuration.dart';
import 'package:flutter/material.dart';

import 'app.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(Configuration(
mapStyleUrl: "https://vector.ehrenamtskarte.app/style.json",
graphqlUrl: "https://api.ehrenamtskarte.app",
child: App()));
}
5 changes: 4 additions & 1 deletion frontend/lib/map/map/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:mapbox_gl/mapbox_gl.dart';

import '../../configuration.dart';

typedef void OnFeatureClickCallback(dynamic feature);
typedef void OnNoFeatureClickCallback();

Expand Down Expand Up @@ -32,10 +34,11 @@ class _MapState extends State<Map> {

@override
Widget build(BuildContext context) {
final config = Configuration.of(context);
return new MapboxMap(
initialCameraPosition: const CameraPosition(
target: Map.initialLocation, zoom: Map.initialZoomLevel),
styleString: "https://vector.ehrenamtskarte.app/style.json",
styleString: config.mapStyleUrl,
myLocationEnabled: widget.myLocationEnabled,
onMapCreated: (controller) {
setState(() {
Expand Down

0 comments on commit a50ac48

Please sign in to comment.