Skip to content

Commit 6ccfec5

Browse files
authored
Merge pull request #5 from CoderJava/build-flavor
Implement build flavor for Android platform
2 parents d0d30e6 + 214d279 commit 6ccfec5

22 files changed

+186
-962
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:pedantic/analysis_options.yaml

android/app/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ android {
5353
signingConfig signingConfigs.debug
5454
}
5555
}
56+
57+
flavorDimensions "production, development"
58+
productFlavors {
59+
production {
60+
resValue "string", "app_name", "News App"
61+
}
62+
development {
63+
resValue "string", "app_name", "dev-News App"
64+
applicationIdSuffix ".development"
65+
versionNameSuffix "-dev"
66+
}
67+
}
5668
}
5769

5870
flutter {

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
FlutterApplication and put your custom class here. -->
88
<application
99
android:name="io.flutter.app.FlutterApplication"
10-
android:label="flutter_news_app"
10+
android:label="@string/app_name"
1111
android:icon="@mipmap/ic_launcher">
1212
<activity
1313
android:name=".MainActivity"

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
13-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1412
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
15-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
16-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1713
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
1814
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
1915
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
@@ -27,8 +23,6 @@
2723
dstPath = "";
2824
dstSubfolderSpec = 10;
2925
files = (
30-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
31-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
3226
);
3327
name = "Embed Frameworks";
3428
runOnlyForDeploymentPostprocessing = 0;
@@ -39,7 +33,6 @@
3933
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4034
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4135
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
42-
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4336
5B3FF722E95A2F7E61CC4A29 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
4437
66E5B3579B8D3925846CAA9D /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
4538
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
@@ -48,7 +41,6 @@
4841
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4942
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
5043
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
51-
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
5244
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
5345
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
5446
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -62,8 +54,6 @@
6254
isa = PBXFrameworksBuildPhase;
6355
buildActionMask = 2147483647;
6456
files = (
65-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
66-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
6757
E67F02A3DCFD50227C270464 /* Pods_Runner.framework in Frameworks */,
6858
);
6959
runOnlyForDeploymentPostprocessing = 0;
@@ -93,9 +83,7 @@
9383
9740EEB11CF90186004384FC /* Flutter */ = {
9484
isa = PBXGroup;
9585
children = (
96-
3B80C3931E831B6300D905FE /* App.framework */,
9786
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
98-
9740EEBA1CF902C7004384FC /* Flutter.framework */,
9987
9740EEB21CF90195004384FC /* Debug.xcconfig */,
10088
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
10189
9740EEB31CF90195004384FC /* Generated.xcconfig */,
@@ -230,17 +218,30 @@
230218
);
231219
runOnlyForDeploymentPostprocessing = 0;
232220
shellPath = /bin/sh;
233-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
221+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
234222
};
235223
5DEAE3B5ED2B6CBD3C04F985 /* [CP] Embed Pods Frameworks */ = {
236224
isa = PBXShellScriptBuildPhase;
237225
buildActionMask = 2147483647;
238226
files = (
239227
);
240228
inputPaths = (
229+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
230+
"${BUILT_PRODUCTS_DIR}/FMDB/FMDB.framework",
231+
"${PODS_ROOT}/../Flutter/Flutter.framework",
232+
"${BUILT_PRODUCTS_DIR}/flutter_stetho/flutter_stetho.framework",
233+
"${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework",
234+
"${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework",
235+
"${BUILT_PRODUCTS_DIR}/url_launcher/url_launcher.framework",
241236
);
242237
name = "[CP] Embed Pods Frameworks";
243238
outputPaths = (
239+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FMDB.framework",
240+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
241+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_stetho.framework",
242+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider.framework",
243+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework",
244+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher.framework",
244245
);
245246
runOnlyForDeploymentPostprocessing = 0;
246247
shellPath = /bin/sh;
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_news_app/src/ui/home/home_screen.dart';
2+
import 'package:flutter_news_app/feature/presentation/page/home/home_page.dart';
33

44
class App extends StatelessWidget {
55
@override
66
Widget build(BuildContext context) {
77
return MaterialApp(
8-
home: HomeScreen(),
8+
title: 'News App',
9+
home: HomePage(),
910
);
1011
}
1112
}

lib/config/base_url_config.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class BaseUrlConfig {
2+
final String baseUrlDevelopment = 'https://bengkelrobot.net:8003/v2';
3+
final String baseUrlProduction = 'https://newsapi.org/v2';
4+
}

lib/config/device_utils.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:device_info/device_info.dart';
2+
3+
enum BuildMode {
4+
DEBUG,
5+
PROFILE,
6+
RELEASE,
7+
}
8+
9+
class DeviceUtils {
10+
11+
static BuildMode currentBuildMode() {
12+
if (const bool.fromEnvironment('dart.vm.product')) {
13+
return BuildMode.RELEASE;
14+
}
15+
var result = BuildMode.PROFILE;
16+
assert(() {
17+
result = BuildMode.DEBUG;
18+
return true;
19+
}());
20+
return result;
21+
}
22+
23+
static Future<AndroidDeviceInfo> androidDeviceInfo() async {
24+
var deviceInfoPlugin = DeviceInfoPlugin();
25+
return deviceInfoPlugin.androidInfo;
26+
}
27+
28+
static Future<IosDeviceInfo> iosDeviceInfo() async {
29+
var deviceInfoPlugin = DeviceInfoPlugin();
30+
return deviceInfoPlugin.iosInfo;
31+
}
32+
33+
}

lib/config/flavor_config.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:meta/meta.dart';
3+
4+
enum Flavor {
5+
DEVELOPMENT,
6+
PRODUCTION,
7+
}
8+
9+
class FlavorValues {
10+
final String baseUrl;
11+
12+
FlavorValues({this.baseUrl});
13+
}
14+
15+
class FlavorConfig {
16+
final Flavor flavor;
17+
final String name;
18+
final Color colorPrimary;
19+
final Color colorPrimaryDark;
20+
final Color colorPrimaryLight;
21+
final Color colorAccent;
22+
final FlavorValues values;
23+
24+
static FlavorConfig _instance;
25+
26+
factory FlavorConfig({
27+
@required Flavor flavor,
28+
Color colorPrimary = Colors.blue,
29+
Color colorPrimaryDark = Colors.blue,
30+
Color colorPrimaryLight = Colors.blue,
31+
Color colorAccent = Colors.blueAccent,
32+
@required FlavorValues values,
33+
}) {
34+
_instance ??= FlavorConfig._internal(
35+
flavor,
36+
enumName(flavor.toString()),
37+
colorPrimary,
38+
colorPrimaryDark,
39+
colorPrimaryLight,
40+
colorAccent,
41+
values,
42+
);
43+
return _instance;
44+
}
45+
46+
FlavorConfig._internal(
47+
this.flavor,
48+
this.name,
49+
this.colorPrimary,
50+
this.colorPrimaryDark,
51+
this.colorPrimaryLight,
52+
this.colorAccent,
53+
this.values,
54+
);
55+
56+
static FlavorConfig get instance {
57+
return _instance;
58+
}
59+
60+
static String enumName(String enumToString) {
61+
var paths = enumToString.split('.');
62+
return paths[paths.length - 1];
63+
}
64+
65+
static bool isProduction() => _instance.flavor == Flavor.PRODUCTION;
66+
67+
static bool isDevelopment() => _instance.flavor == Flavor.DEVELOPMENT;
68+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:flutter/material.dart';
2+
3+
class HomePage extends StatelessWidget {
4+
@override
5+
Widget build(BuildContext context) {
6+
return Scaffold(
7+
body: Center(
8+
child: Text('Hello World'),
9+
)
10+
);
11+
}
12+
}

lib/main.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)