File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change
1
+ /// Contains the hard-coded settings per flavor.
2
+ class FlavorSettings {
3
+ final String apiBaseUrl;
4
+ // TODO Add any additional flavor-specific settings here.
5
+
6
+ FlavorSettings .dev () : apiBaseUrl = 'https://dev.flutter-flavors.chwe.at' ;
7
+
8
+ FlavorSettings .live () : apiBaseUrl = 'https://flutter-flavors.chwe.at' ;
9
+ }
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter/services.dart' ;
3
+
4
+ import 'flavor_settings.dart' ;
5
+
6
+ Future <void > main () async {
7
+ // NOTE: This is required for accessing the method channel before runApp().
8
+ WidgetsFlutterBinding .ensureInitialized ();
9
+
10
+ final settings = await _getFlavorSettings ();
11
+ print ('API URL ${settings .apiBaseUrl }' );
2
12
3
- void main () {
4
13
runApp (MyApp ());
5
14
}
6
15
16
+ Future <FlavorSettings > _getFlavorSettings () async {
17
+ String flavor =
18
+ await const MethodChannel ('flavor' ).invokeMethod <String >('getFlavor' );
19
+
20
+ print ('STARTED WITH FLAVOR $flavor ' );
21
+
22
+ if (flavor == 'dev' ) {
23
+ return FlavorSettings .dev ();
24
+ } else if (flavor == 'live' ) {
25
+ return FlavorSettings .live ();
26
+ } else {
27
+ throw Exception ("Unknown flavor: $flavor " );
28
+ }
29
+ }
30
+
7
31
class MyApp extends StatelessWidget {
8
32
// This widget is the root of your application.
9
33
@override
You can’t perform that action at this time.
0 commit comments