Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,20 @@ iOS Production

### Central log library:

Can be used for logging different details. All methods are static thus no instance of Console is required. Console.info() method will print info in blue color font, Console.success() method will print log in green color font, Console.warning() method will print log in yellow color font, and Console.danger() method will print log in red color font. The files reside in `lib/vaahextendflutter/log/` folder.
Can be used for logging different details. All methods are static thus no instance of Console is required. Console.info() method will print info in blue color font, Console.success() method will print log in green color font, Console.warning() method will print log in yellow color font, and Console.danger() method will print log in red color font. The files reside in `lib/vaahextendflutter/log/` folder.

### Environment and Version Tag

Environment and Version Tag can be seen on every page unless you set `showEnvAndVersionTag` for your Environment configuration in `env.dart` file. You can change color of tag by setting `envAndVersionTagColor` variable for your Environment configuration.

NOTE: `Remember showEnvAndVersionTag for production should always be false in Environment configuration in `env.dart` file.`
```dart
'production': defaultConfig.copyWith(
...
showEnvAndVersionTag: false,
),
```

NOTE: Whenever you create a new screen/ page, wrap the body with `TagWrapper` class.

You can use alignment and margin properties for achieving desired results using TagWrapper.
36 changes: 25 additions & 11 deletions lib/env.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:team/vaahextendflutter/log/console.dart';

import 'vaahextendflutter/log/console.dart';

// After changing any const you will need to restart the app (Hot-reload won't work).

// Version and build
const String version = '1.0.0'; // version format 1.0.0 (major.minor.patch)
const String build = '2022100901'; // build no format 'YYYYMMDDNUMBER'

EnvironmentConfig defaultConfig = EnvironmentConfig(
EnvironmentConfig defaultConfig = const EnvironmentConfig(
envType: 'default',
version: version,
build: build,
Expand All @@ -18,6 +20,8 @@ EnvironmentConfig defaultConfig = EnvironmentConfig(
analyticsId: '',
enableConsoleLogs: true,
enableLocalLogs: true,
showEnvAndVersionTag: true,
envAndVersionTagColor: Colors.red,
);

// To add new configuration add new key, value pair in envConfigs
Expand All @@ -38,6 +42,7 @@ Map<String, EnvironmentConfig> envConfigs = {
envType: 'production',
enableConsoleLogs: false,
enableLocalLogs: false,
showEnvAndVersionTag: false,
),
};

Expand Down Expand Up @@ -65,16 +70,18 @@ class EnvController extends GetxController {
}

class EnvironmentConfig {
String envType;
String version;
String build;
String baseUrl;
String apiBaseUrl;
String analyticsId;
bool enableConsoleLogs;
bool enableLocalLogs;
final String envType;
final String version;
final String build;
final String baseUrl;
final String apiBaseUrl;
final String analyticsId;
final bool enableConsoleLogs;
final bool enableLocalLogs;
final bool showEnvAndVersionTag;
final Color envAndVersionTagColor;

EnvironmentConfig({
const EnvironmentConfig({
required this.envType,
required this.version,
required this.build,
Expand All @@ -83,6 +90,8 @@ class EnvironmentConfig {
required this.analyticsId,
required this.enableConsoleLogs,
required this.enableLocalLogs,
required this.showEnvAndVersionTag,
required this.envAndVersionTagColor,
});

EnvironmentConfig copyWith({
Expand All @@ -94,6 +103,8 @@ class EnvironmentConfig {
String? analyticsId,
bool? enableConsoleLogs,
bool? enableLocalLogs,
bool? showEnvAndVersionTag,
Color? envAndVersionTagColor,
}) {
return EnvironmentConfig(
envType: envType ?? this.envType,
Expand All @@ -104,6 +115,9 @@ class EnvironmentConfig {
analyticsId: analyticsId ?? this.analyticsId,
enableConsoleLogs: enableConsoleLogs ?? this.enableConsoleLogs,
enableLocalLogs: enableLocalLogs ?? this.enableLocalLogs,
showEnvAndVersionTag: showEnvAndVersionTag ?? this.showEnvAndVersionTag,
envAndVersionTagColor:
envAndVersionTagColor ?? this.envAndVersionTagColor,
);
}
}
14 changes: 10 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:get/get.dart';

import 'env.dart';
import 'vaahextendflutter/log/console.dart';
import 'vaahextendflutter/base/base_stateful.dart';
import 'vaahextendflutter/tag/tag.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -42,7 +44,7 @@ class TeamHomePage extends StatefulWidget {
State<TeamHomePage> createState() => _TeamHomePageState();
}

class _TeamHomePageState extends State<TeamHomePage> {
class _TeamHomePageState extends BaseStateful<TeamHomePage> {
late EnvController envController;

@override
Expand All @@ -53,11 +55,15 @@ class _TeamHomePageState extends State<TeamHomePage> {

@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
appBar: AppBar(),
body: Center(
child: Text(
'${envController.config.envType} ${envController.config.version}+${envController.config.build}'),
body: const TagWrapper(
alignment: Alignment.topCenter,
margin: EdgeInsets.all(10),
child: Center(
child: Text('Webreinvent'),
),
),
);
}
Expand Down
40 changes: 40 additions & 0 deletions lib/vaahextendflutter/base/base_stateful.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';

import '../services/screen_util.dart';

abstract class BaseStateful<T extends StatefulWidget> extends State<T>
with DynamicSize {
// Context valid to create providers
@mustCallSuper
@protected
void initDependencies(BuildContext context) {
// eg. Connectivity controller (Which checks network connectivity)
}

@protected
void afterFirstBuild(BuildContext context) {}

@mustCallSuper
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
afterFirstBuild(context);
});
}

@override
void setState(VoidCallback fn) {
if (mounted) {
super.setState(fn);
}
}

@mustCallSuper
@override
Widget build(BuildContext context) {
initDependencies(context);
initDynamicSize(context);
return const SizedBox();
}
}
27 changes: 27 additions & 0 deletions lib/vaahextendflutter/base/base_stateless.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import '../services/screen_util.dart';

abstract class BaseStateless extends StatelessWidget with DynamicSize {
const BaseStateless({super.key});

// Context valid to create controllers
@mustCallSuper
@protected
void initDependencies(BuildContext context) {
// eg. Connectivity controller
}

@protected
void afterFirstBuild(BuildContext context) {}

@mustCallSuper
@override
Widget build(BuildContext context) {
initDependencies(context);
initDynamicSize(context);
WidgetsBinding.instance.addPostFrameCallback((_) {
afterFirstBuild(context);
});
return const SizedBox();
}
}
1 change: 1 addition & 0 deletions lib/vaahextendflutter/log/console.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:colorize/colorize.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../env.dart';

class Console {
Expand Down
Loading