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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ migrate_working_dir/
*.iws
.idea/

# VS code
.vscode/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ flutter pub get

## Environments

### To run app in `production` mode use command
### To run app in `production` mode use command
```
flutter run --dart-define="environment=production"
```
Expand All @@ -47,7 +47,7 @@ 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
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"
Expand All @@ -69,15 +69,18 @@ flutter pub outdated
<hr />

## Project structure and coding conventions:

### [Official dart conventions](https://dart.dev/guides/language/effective-dart/style)

- 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.
- Classes, Enums, Typedefs, and extensions naming convention: UpperCamelCase.
- Variables, constants, parameters naming convention: lowerCamelCase.
- Method/ functions naming conevntion: lowerCamelCase.
- Method/ functions naming convention: lowerCamelCase.
- Use relative path
- ✘ `import 'package:demo/home.dart';` -> This should be avoided.
- ✔ `import './home.dart';` -> Correct way
- ✘ `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
Expand All @@ -88,7 +91,7 @@ Android Production
iOS Production
- universal package: `com.webreinvent.team`

## VaahExtendedFlutter
## VaahExtendFlutter

### → Central log library:

Expand All @@ -108,7 +111,7 @@ NOTE: `Remember showEnvAndVersionTag for production should always be false in En

#### NOTE: You have to write below code in MaterialApp, and that will show tag panel on each screen. You don't have to wrap any other screen/ widget, or you don't have to extend any screen/ any widget with TagPanelHost.

In file cotaining material app paste this code after imports
In file containing material app paste this code after imports
```dart
final _navigatorKey = GlobalKey<NavigatorState>();
```
Expand All @@ -121,9 +124,9 @@ builder: (BuildContext context, Widget? child) {
);
},
```
This panel uses EnvController, thus dependens on env.dart file.
This panel uses EnvController, thus depends on env.dart file.

### → Dynamic fontsize, dynamic width, dynamic height depending on device size
### → Dynamic font size, dynamic width, dynamic height depending on device size

To use it directly by importing `screen_util.dart` check Usage: comment in `screen_util.dart` file.

Expand Down Expand Up @@ -156,9 +159,9 @@ SizedBox(
### → Base widgets
`vaahextendflutter/base` folder contains all the base classes/ widgets.

BaseStateless and BaseStateful are used when dev wants to init/ add dependencies in many screens and don't want to write same logic in every file, so they write the logic in base files only. eg. internet connectivity checker, dynamic size dependency, etc.
BaseStateless and BaseStateful are used when dev wants to init/ add dependencies in many screens and don't want to write same logic in every file, so they write the logic in base files only. e.g. internet connectivity checker, dynamic size dependency, etc.

so base class implements those logics and other classes can extend the base classes.
So base class implements those logics and other classes can extend the base classes.

### → Helpers
Most common constants and styles used in whole app.
Expand Down
35 changes: 35 additions & 0 deletions lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'env.dart';

import 'routes/routes.dart';
import 'app_theme.dart';
import 'vaahextendflutter/tag/tag_panel.dart';
import 'view/pages/home.dart';

final _navigatorKey = GlobalKey<NavigatorState>();

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

@override
Widget build(BuildContext context) {
EnvironmentConfig env = EnvironmentConfig.getEnvConfig();
return GetMaterialApp(
title: env.appTitle,
theme: ThemeData(
primarySwatch: AppTheme.colors['primary'],
),
onGenerateInitialRoutes: (String initialRoute) {
return [TeamHomePage.route()];
},
onGenerateRoute: onGenerateRoute,
builder: (BuildContext context, Widget? child) {
return TagPanelHost(
navigatorKey: _navigatorKey,
child: child!,
);
},
);
}
}
32 changes: 32 additions & 0 deletions lib/app_theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';

import 'vaahextendflutter/base/base_theme.dart';

class AppTheme {
static final Map<String, MaterialColor> colors = Map.of(BaseTheme.colors);

static void init() {
// colors['primary'] = pink;
// colors['secondary'] = gray;
}
}



// To define new color developer should visit https://colors.eva.design/

const MaterialColor pink = MaterialColor(
0xFFFF1F6A,
<int, Color>{
50: Color(0xFFFFD4D2),
100: Color(0xFFFFD4D2),
200: Color(0xFFFFA5A8),
300: Color(0xFFFF788B),
400: Color(0xFFFF577E),
500: Color(0xFFFF1F6A),
600: Color(0xFFDB166B),
700: Color(0xFFB70F68),
800: Color(0xFF930960),
900: Color(0xFF7A055A),
},
);
24 changes: 24 additions & 0 deletions lib/controllers/base_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:get/get.dart';

import '../env.dart';
import '../app_theme.dart';
import '../vaahextendflutter/helpers/console.dart';
import '../vaahextendflutter/services/api.dart';

class BaseController extends GetxController {
Future<void> init() async {
String environment =
const String.fromEnvironment('environment', defaultValue: 'default');
final EnvController envController = Get.put(
EnvController(
environment,
),
);
Console.info('Env Type: ${envController.config.envType}');
Console.info(
'Version: ${envController.config.version}+${envController.config.build}',
);
await Api.initApi();
AppTheme.init();
}
}
43 changes: 34 additions & 9 deletions lib/env.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'vaahextendflutter/log/console.dart';
import 'app_theme.dart';
import 'vaahextendflutter/helpers/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 = const EnvironmentConfig(
final EnvironmentConfig defaultConfig = EnvironmentConfig(
appTitle: 'WebReinvent Team',
appTitleShort: 'Team',
envType: 'default',
version: version,
build: build,
backendUrl: '', // base url or backend url
apiUrl: '', // api base url
firebaseId: '', // firebase id
backendUrl: '',
apiUrl: 'https://apivoid.herokuapp.com',
timeoutLimit: 60 * 1000, // 60 seconds
firebaseId: '',
enableConsoleLogs: true,
enableLocalLogs: true,
enableApiLogs: true,
showEnvAndVersionTag: true,
envAndVersionTagColor: Color(
0xAA000000), // first 2 digit after 0x represents the opacity where CC being max and 00 being min
envAndVersionTagColor: AppTheme.colors['black']!.withOpacity(0.7),
);

// To add new configuration add new key, value pair in envConfigs
Expand Down Expand Up @@ -71,54 +76,74 @@ class EnvController extends GetxController {
}

class EnvironmentConfig {
final String appTitle;
final String appTitleShort;
final String envType;
final String version;
final String build;
final String backendUrl;
final String apiUrl;
final String firebaseId;
final int timeoutLimit;
final bool enableConsoleLogs;
final bool enableLocalLogs;
final bool enableApiLogs;
final bool showEnvAndVersionTag;
final Color envAndVersionTagColor;

const EnvironmentConfig({
required this.appTitle,
required this.appTitleShort,
required this.envType,
required this.version,
required this.build,
required this.backendUrl,
required this.apiUrl,
required this.firebaseId,
required this.timeoutLimit,
required this.enableConsoleLogs,
required this.enableLocalLogs,
required this.enableApiLogs,
required this.showEnvAndVersionTag,
required this.envAndVersionTagColor,
});

static EnvironmentConfig getEnvConfig() {
EnvController envController = Get.find<EnvController>();
return envController.config;
}

EnvironmentConfig copyWith({
String? appTitle,
String? appTitleShort,
String? envType,
String? version,
String? build,
String? backendUrl,
String? apiUrl,
String? firebaseId,
int? timeoutLimit,
bool? enableConsoleLogs,
bool? enableLocalLogs,
bool? enableApiLogs,
bool? showEnvAndVersionTag,
Color? envAndVersionTagColor,
}) {
return EnvironmentConfig(
appTitle: appTitle ?? this.appTitle,
appTitleShort: appTitleShort ?? this.appTitleShort,
envType: envType ?? this.envType,
version: version ?? this.version,
build: build ?? this.build,
backendUrl: backendUrl ?? this.backendUrl,
apiUrl: apiUrl ?? this.apiUrl,
firebaseId: firebaseId ?? this.firebaseId,
timeoutLimit: timeoutLimit ?? this.timeoutLimit,
enableConsoleLogs: enableConsoleLogs ?? this.enableConsoleLogs,
enableLocalLogs: enableLocalLogs ?? this.enableLocalLogs,
enableApiLogs: enableApiLogs ?? this.enableApiLogs,
showEnvAndVersionTag: showEnvAndVersionTag ?? this.showEnvAndVersionTag,
envAndVersionTagColor:
envAndVersionTagColor ?? this.envAndVersionTagColor,
envAndVersionTagColor: envAndVersionTagColor ?? this.envAndVersionTagColor,
);
}
}
Loading