Last updated:
0 purchases
flavorbanner
flavorbanner #
Flavor Banner is a package that make easy to configure flavors and add a banner to show info about device.
ScreenShots #
Usage #
install
Add to yaml
dependencies:
flavorbanner: $latest_version
copied to clipboard
create mains
You have to create different mains for your flavors, for example:
main_test.dart
main_development.dart
main_staging.dart
main_production.dart
import
import 'package:flavorbanner/flavorbanner.dart'
copied to clipboard
create mains
Each one of your mains have to look like this:
void main() {
FlavorConfig(
flavor: Flavor.DEV,
color: Colors.grey,
values: FlavorValues(
baseUrl: "https://dev.com/",
showBanner: true,
),
);
runApp(MyApp());
}
copied to clipboard
The allowed flavor types are TEST, DEV, STAGING, PROD
enum Flavor { TEST, DEV, STAGING, PROD }
copied to clipboard
You usually does not want to show banner in production so you can set showbanner value to false.
void main() {
FlavorConfig(
flavor: Flavor.PROD,
color: Colors.grey,
values: FlavorValues(
baseUrl: "https://dev.com/",
showBanner: false,
),
);
runApp(MyApp());
}
copied to clipboard
wrap app in FlavorBanner
In order to show your banner in all pages you have to update your materialApp builder like this
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FirstPage(),
builder: (context, child) => FlavorBanner(
child: child,
),
);
}
}
copied to clipboard
use values
By default, you can only set baseUrl and showbanner per flavor. You can get this configuration in any place of your app using this:
Text(FlavorConfig.instance.values.baseUrl)
copied to clipboard
extend values
You can use your own config values, for example:
import 'package:flavorbanner/flavorbanner.dart'
class CustomValues extends FlavorValues {
CustomValues({
this.baseUrl,
this.showBanner = false,
this.mapsApiKey,
}) ;
final String baseUrl, mapsApiKey;
final bool showBanner;
}
copied to clipboard
Then you can use this in your main:
void main() {
FlavorConfig(
flavor: Flavor.PROD,
color: Colors.red,
values: CustomValues(
baseUrl: "https://prod.com/",
mapsApiKey: 'mapsApiKey',
),
);
runApp(MyApp());
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.