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
76 changes: 69 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,88 @@ Dart and flutter versions: the project requires
and flutter version >=3.3.4
```

to change minimum requirement of dart and flutter change the `sdk and flutter` versions under `environment` in the `pubspec.yaml` file.
To change minimum requirement of dart and flutter change the `sdk and flutter` versions under `environment` in the `pubspec.yaml` file.
<hr />

## Setup

run the command: `flutter pub get`
Run the command:
```
flutter pub get
```

## Environments

### To run app in `production` mode use command
```
flutter run --dart-define="environment=production"
```

### To run app in `staging/ QA` mode use command
```
flutter run --dart-define="environment=stage"
```

### To run app in `develop` mode use command
```
flutter run --dart-define="environment=develop"
```

### For Android production build use command
```
flutter build apk --dart-define="environment=production"
```

### For iOS production build use command
```
flutter build ipa --dart-define="environment=production"
```

### How to create a new environment:

Go to `lib/env.dart`, find `envConfigs` variable and add configuration for the environment you want to create. example: for `testing` environment add `'testing'` key and value. And in commands pass your environment name
```
// for example if environment name is testing then
flutter run --dart-define="environment=testing"
```
<hr />

### Packages:
In pubspec.yaml file > Add essential packages in dependencies, and packages that a developer need in dev_dependencies.
## Packages:
In `pubspec.yaml` file > Add essential packages in `dependencies`, and packages that a developer need in `dev_dependencies`.

To automatically upgrade your package dependencies to the latest versions consider running `flutter pub upgrade --major-versions`. To see which dependencies have newer versions available, run `flutter pub outdated`
To automatically upgrade your package dependencies to the latest versions consider running
```
flutter pub upgrade --major-versions
```

To see which dependencies have newer versions available, run
```
flutter pub outdated
```
<hr />

### Project structure:
## Project structure and coding conventions:
- 2 spaces for indentation
- test files have `_test.ext` suffix in the file name > example `widget_test.dart`
- Libraries, packages, directories, and source files name convention: snake_case(lowercase_with_underscores).
- Classes, enums, typedefs, and extensions naming conevntion: UpperCamelCase.
- Variables, constants, parameters naming convention: lowerCamelCase.
- Method/ functions naming conevntion: lowerCamelCase.
- Use relative path
- ✘ `import 'package:demo/home.dart';` -> This should be avoided.
- ✔ `import './home.dart';` -> Correct way
- to fix imports you can use [dart-import](https://marketplace.visualstudio.com/items?itemName=luanpotter.dart-import)
- Avoid using as instead, use is operator
- Avoid print()/ debugPrint() calls

Android Production
- universal package: `com.webreinvent.team`

iOS Production
- universal package: `com.webreinvent.team`
- universal package: `com.webreinvent.team`

## VaahExtendedFlutter

### 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.
109 changes: 109 additions & 0 deletions lib/env.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import 'dart:io';

import 'package:get/get.dart';
import 'package:team/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(
envType: 'default',
version: version,
build: build,
baseUrl: '',
apiBaseUrl: '',
analyticsId: '',
enableConsoleLogs: true,
enableLocalLogs: true,
);

// To add new configuration add new key, value pair in envConfigs
Map<String, EnvironmentConfig> envConfigs = {
// Do not remove default config
'default': defaultConfig.copyWith(
envType: 'default',
),
'develop': defaultConfig.copyWith(
envType: 'develop',
enableLocalLogs: false,
),
'stage': defaultConfig.copyWith(
envType: 'stage',
enableLocalLogs: false,
),
'production': defaultConfig.copyWith(
envType: 'production',
enableConsoleLogs: false,
enableLocalLogs: false,
),
};

class EnvController extends GetxController {
late EnvironmentConfig _config;
EnvironmentConfig get config => _config;

EnvController(String environment) {
try {
_config = getSpecificConfig(environment);
update();
} catch (e) {
Console.danger(e.toString());
exit(0);
}
}

EnvironmentConfig getSpecificConfig(String key) {
bool configExists = envConfigs.containsKey(key);
if (configExists) {
return envConfigs[key]!;
}
throw Exception('Environment configuration not found for key: $key');
}
}

class EnvironmentConfig {
String envType;
String version;
String build;
String baseUrl;
String apiBaseUrl;
String analyticsId;
bool enableConsoleLogs;
bool enableLocalLogs;

EnvironmentConfig({
required this.envType,
required this.version,
required this.build,
required this.baseUrl,
required this.apiBaseUrl,
required this.analyticsId,
required this.enableConsoleLogs,
required this.enableLocalLogs,
});

EnvironmentConfig copyWith({
String? envType,
String? version,
String? build,
String? baseUrl,
String? apiBaseUrl,
String? analyticsId,
bool? enableConsoleLogs,
bool? enableLocalLogs,
}) {
return EnvironmentConfig(
envType: envType ?? this.envType,
version: version ?? this.version,
build: build ?? this.build,
baseUrl: baseUrl ?? this.baseUrl,
apiBaseUrl: apiBaseUrl ?? this.apiBaseUrl,
analyticsId: analyticsId ?? this.analyticsId,
enableConsoleLogs: enableConsoleLogs ?? this.enableConsoleLogs,
enableLocalLogs: enableLocalLogs ?? this.enableLocalLogs,
);
}
}
30 changes: 27 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'env.dart';
import 'vaahextendflutter/log/console.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();
String environment =
const String.fromEnvironment('environment', defaultValue: 'default');
final EnvController envController = Get.put(
EnvController(
environment,
),
);
Console.info('>>>>> ${envController.config.envType}');
Console.info(
'>>>>> ${envController.config.version}+${envController.config.build}',
);
runApp(const TeamApp());
}

class TeamApp extends StatelessWidget {
const TeamApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -28,12 +43,21 @@ class TeamHomePage extends StatefulWidget {
}

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

@override
void initState() {
envController = Get.find<EnvController>();
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: const Center(
child: Text('WebReinvent'),
body: Center(
child: Text(
'${envController.config.envType} ${envController.config.version}+${envController.config.build}'),
),
);
}
Expand Down
82 changes: 82 additions & 0 deletions lib/vaahextendflutter/log/console.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'package:colorize/colorize.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../env.dart';

class Console {
static void printChunks(Colorize text) {
final RegExp pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(text.toString()).forEach(
(RegExpMatch match) => debugPrint(
match.group(0),
),
);
}

static void printLog(Colorize text) {
bool envControllerExists = Get.isRegistered<EnvController>();
if (envControllerExists) {
EnvController envController = Get.find<EnvController>();
if (envController.config.enableConsoleLogs == false) return;
}
Console.printChunks(text);
}

static void log(String text, [Object? data]) {
Colorize txt = Colorize(text);
Console.printLog(txt);

if (data != null) {
Colorize dataColor = Colorize(data.toString());
Console.printLog(dataColor);
}
}

static void info(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.blue();
Console.printLog(txt);

if (data != null) {
Colorize dataColor = Colorize(data.toString());
dataColor.blue();
Console.printLog(dataColor);
}
}

static void success(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.green();
Console.printLog(txt);

if (data != null) {
Colorize dataColor = Colorize(data.toString());
dataColor.green();
Console.printLog(dataColor);
}
}

static void warning(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.yellow();
Console.printLog(txt);

if (data != null) {
Colorize dataColor = Colorize(data.toString());
dataColor.yellow();
Console.printLog(dataColor);
}
}

static void danger(String text, [Object? data]) {
Colorize txt = Colorize(text);
txt.red();
Console.printLog(txt);

if (data != null) {
Colorize dataColor = Colorize(data.toString());
dataColor.red();
Console.printLog(dataColor);
}
}
}
1 change: 1 addition & 0 deletions lib/vaahextendflutter/log/local.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
colorize:
dependency: "direct main"
description:
name: colorize
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -67,6 +74,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
get:
dependency: "direct main"
description:
name: get
url: "https://pub.dartlang.org"
source: hosted
version: "4.6.5"
lints:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
get: ^4.6.5
colorize: ^3.0.0

dev_dependencies:
flutter_test:
Expand Down