-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement build flavor for Android platform
- Loading branch information
Showing
22 changed files
with
186 additions
and
962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:pedantic/analysis_options.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_news_app/src/ui/home/home_screen.dart'; | ||
import 'package:flutter_news_app/feature/presentation/page/home/home_page.dart'; | ||
|
||
class App extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: HomeScreen(), | ||
title: 'News App', | ||
home: HomePage(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class BaseUrlConfig { | ||
final String baseUrlDevelopment = 'https://bengkelrobot.net:8003/v2'; | ||
final String baseUrlProduction = 'https://newsapi.org/v2'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:device_info/device_info.dart'; | ||
|
||
enum BuildMode { | ||
DEBUG, | ||
PROFILE, | ||
RELEASE, | ||
} | ||
|
||
class DeviceUtils { | ||
|
||
static BuildMode currentBuildMode() { | ||
if (const bool.fromEnvironment('dart.vm.product')) { | ||
return BuildMode.RELEASE; | ||
} | ||
var result = BuildMode.PROFILE; | ||
assert(() { | ||
result = BuildMode.DEBUG; | ||
return true; | ||
}()); | ||
return result; | ||
} | ||
|
||
static Future<AndroidDeviceInfo> androidDeviceInfo() async { | ||
var deviceInfoPlugin = DeviceInfoPlugin(); | ||
return deviceInfoPlugin.androidInfo; | ||
} | ||
|
||
static Future<IosDeviceInfo> iosDeviceInfo() async { | ||
var deviceInfoPlugin = DeviceInfoPlugin(); | ||
return deviceInfoPlugin.iosInfo; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
enum Flavor { | ||
DEVELOPMENT, | ||
PRODUCTION, | ||
} | ||
|
||
class FlavorValues { | ||
final String baseUrl; | ||
|
||
FlavorValues({this.baseUrl}); | ||
} | ||
|
||
class FlavorConfig { | ||
final Flavor flavor; | ||
final String name; | ||
final Color colorPrimary; | ||
final Color colorPrimaryDark; | ||
final Color colorPrimaryLight; | ||
final Color colorAccent; | ||
final FlavorValues values; | ||
|
||
static FlavorConfig _instance; | ||
|
||
factory FlavorConfig({ | ||
@required Flavor flavor, | ||
Color colorPrimary = Colors.blue, | ||
Color colorPrimaryDark = Colors.blue, | ||
Color colorPrimaryLight = Colors.blue, | ||
Color colorAccent = Colors.blueAccent, | ||
@required FlavorValues values, | ||
}) { | ||
_instance ??= FlavorConfig._internal( | ||
flavor, | ||
enumName(flavor.toString()), | ||
colorPrimary, | ||
colorPrimaryDark, | ||
colorPrimaryLight, | ||
colorAccent, | ||
values, | ||
); | ||
return _instance; | ||
} | ||
|
||
FlavorConfig._internal( | ||
this.flavor, | ||
this.name, | ||
this.colorPrimary, | ||
this.colorPrimaryDark, | ||
this.colorPrimaryLight, | ||
this.colorAccent, | ||
this.values, | ||
); | ||
|
||
static FlavorConfig get instance { | ||
return _instance; | ||
} | ||
|
||
static String enumName(String enumToString) { | ||
var paths = enumToString.split('.'); | ||
return paths[paths.length - 1]; | ||
} | ||
|
||
static bool isProduction() => _instance.flavor == Flavor.PRODUCTION; | ||
|
||
static bool isDevelopment() => _instance.flavor == Flavor.DEVELOPMENT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class HomePage extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: Text('Hello World'), | ||
) | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_news_app/app.dart'; | ||
import 'package:flutter_news_app/config/base_url_config.dart'; | ||
import 'package:flutter_news_app/config/flavor_config.dart'; | ||
import 'package:flutter_stetho/flutter_stetho.dart'; | ||
|
||
void main() async { | ||
FlavorConfig( | ||
flavor: Flavor.DEVELOPMENT, | ||
values: FlavorValues(baseUrl: BaseUrlConfig().baseUrlDevelopment), | ||
); | ||
await Stetho.initialize(); | ||
runApp(App()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_news_app/app.dart'; | ||
import 'package:flutter_news_app/config/base_url_config.dart'; | ||
import 'package:flutter_news_app/config/flavor_config.dart'; | ||
|
||
void main() async { | ||
FlavorConfig( | ||
flavor: Flavor.PRODUCTION, | ||
values: FlavorValues(baseUrl: BaseUrlConfig().baseUrlProduction), | ||
); | ||
runApp(App()); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.