Skip to content
Permalink
Browse files

Split app into flavors in Dart

  • Loading branch information...
orestesgaolin committed Jul 10, 2019
1 parent cef5fbf commit a4c7ef8e351676825b422839baa539ecf7f021d9
Showing with 45 additions and 5 deletions.
  1. +5 −0 lib/app_config.dart
  2. +7 −2 lib/{main.dart → main_common.dart}
  3. +10 −0 lib/main_dev.dart
  4. +10 −0 lib/main_prod.dart
  5. +10 −0 lib/main_tst.dart
  6. +3 −3 test/widget_test.dart
@@ -0,0 +1,5 @@
class AppConfig {
AppConfig(this.flavor);

final String flavor;
}
@@ -1,8 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_flavors/app_config.dart';

void main() => runApp(MyApp());
void mainCommon(AppConfig config) => runApp(MyApp(config));

class MyApp extends StatelessWidget {
MyApp(this.config);

final AppConfig config;

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
@@ -20,7 +25,7 @@ class MyApp extends StatelessWidget {
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
home: MyHomePage(title: 'Flutter: ${config.flavor}'),
);
}
}
@@ -0,0 +1,10 @@
import 'dart:async';

import 'package:flutter_flavors/app_config.dart';
import 'package:flutter_flavors/main_common.dart';

Future<void> main() async {
final config = AppConfig('dev');

mainCommon(config);
}
@@ -0,0 +1,10 @@
import 'dart:async';

import 'package:flutter_flavors/app_config.dart';
import 'package:flutter_flavors/main_common.dart';

Future<void> main() async {
final config = AppConfig('prod');

mainCommon(config);
}
@@ -0,0 +1,10 @@
import 'dart:async';

import 'package:flutter_flavors/app_config.dart';
import 'package:flutter_flavors/main_common.dart';

Future<void> main() async {
final config = AppConfig('tst');

mainCommon(config);
}
@@ -6,14 +6,14 @@
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_flavors/app_config.dart';
import 'package:flutter_flavors/main_common.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:flutter_flavors/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
await tester.pumpWidget(MyApp(AppConfig('test')));

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);

0 comments on commit a4c7ef8

Please sign in to comment.
You can’t perform that action at this time.