Skip to content

Commit

Permalink
New changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmysonJack committed Feb 6, 2024
1 parent e5edb5c commit 4c1c29d
Show file tree
Hide file tree
Showing 34 changed files with 2,559 additions and 1,338 deletions.
48 changes: 45 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'loading_environment.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
initApp(
appColors: AppColors(),
appName: 'Shared Components',
loadEnvFile: () async {
// debugDisableShadows = true;
Expand All @@ -20,9 +21,10 @@ void main() {
child: Scaffold(
body: SideNavigation(
appBarPosition: AppBarPosition.side,
showSideNav: true,
version: '2.0.3',
topAppBarDetails: TopAppBarDetails(
title: 'Top Bar',
title: 'DHMS | LUGALO',
menuItems: [
MenuItem<String>(
title: 'Change Password',
Expand Down Expand Up @@ -67,8 +69,48 @@ void main() {
children: [
RouteService.childRoute(
routeName: '/dashboard',
child: const SizedBox(
child: UserManager(),
child: SizedBox(
child: UserManager(
roleConfig: RoleConfig(
assignPermissionToRoleEndpoint: '',
deleteRoleEndpoint: 'deleteRole',
getPermissionsEndpoint: 'getPermissions',
getPermissionsResponseField:
'uid name description active',
getRoleResponseFields: 'uid name description',
getRolesEndpoint: 'getRoles',
saveRoleEndpoint: 'saveRole',
saveRoleInputFieldName: 'roleDto',
saveRoleInputType: 'SaveRoleDtoInput',
deleteUIdFieldName: 'roleUid'),
userConfig: UserConfig(
assignRoleToUserEndpoint: 'assignRoleToUser',
deleteUserEndpoint: 'deleteUser',
getRolesByUserEndpoint: 'getRolesByUser',
getRolesByUserResponseFields:
'uid name description active',
getUsersEndpoint: 'getUsers',
saveUserEndpoint: 'saveUser',
saveUserInputFieldName: 'userDto',
saveUserInputType: 'SaveUserDtoInput',
deleteUIdFieldName: 'uid',
getUserResponseFields: '''
name
email
facility{
uid
name
}
accountNonExpired
credentialsNonExpired
lastLogin
phoneNumber
enabled
isActive
uid
''',
),
),
)),
ChildRoute('/user-management',
child: (context, args) => const SizedBox(
Expand Down
2 changes: 1 addition & 1 deletion google-ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ linter:
# Might become obsolete with Non-Nullable types
# pedantic: enabled
# http://dart-lang.github.io/linter/lints/always_require_non_null_named_parameters.html
- always_require_non_null_named_parameters
# - always_require_non_null_named_parameters

# Since dart 2.0 dart is a sound language, specifying types is not required anymore.
# `var foo = 10;` is enough information for the compiler to make foo a int.
Expand Down
3 changes: 2 additions & 1 deletion lib/shared_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export 'src/shared/top-app-bar/user_profile_popup_menu_item.dart';
export 'src/shared/animated-expansion-tile/mobile-data-table.dart';
export 'src/shared/permissions-widget/permission_set.dart';
export 'src/shared/customPdfViewer/customPdfViewer.dart';
export 'src/shared/user-management/users-manager.dart';
export 'src/shared/user-management/users_manager.dart';
export 'src/shared/user-management/role-widget.dart';
export 'src/service/navigation.service.dart';
export 'src/service/route.service.dart';
export 'package:get/get.dart'
Expand Down
4 changes: 2 additions & 2 deletions lib/src/customDate/date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ class _CustomDateState extends State<CustomDate> {
decoration: InputDecoration(
suffixIcon: const Icon(Icons.date_range),
labelText: widget.labelText,
filled: widget.filled,
fillColor: Theme.of(context).cardColor,
// filled: widget.filled,
// fillColor: Theme.of(context).cardColor,
),
onTap: widget.onTap ??
() {
Expand Down
9 changes: 9 additions & 0 deletions lib/src/environment/system.env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Environment {
String? _serverUrl;
String? _clientId;
String? _clientSecret;
String? _port;
static Environment? _instance;

static Environment getInstance() {
Expand Down Expand Up @@ -32,4 +33,12 @@ class Environment {
String? getServerUrl() {
return _serverUrl;
}

setServerUrlPort(String port) {
_port = port;
}

String? getServerUrlPort() {
return _port;
}
}
6 changes: 3 additions & 3 deletions lib/src/init-main/app.widget.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_component/shared_component.dart';

class AppWidget extends StatelessWidget {
final String appName;
const AppWidget({super.key, required this.appName});
final AppColors appColors;
const AppWidget({super.key, required this.appName, required this.appColors});

@override
Widget build(BuildContext context) {
Expand All @@ -18,7 +18,7 @@ class AppWidget extends StatelessWidget {
return Obx(() {
ThemeController.getInstance().isDarkTheme.value;
return Theme(
data: ThemeController.getInstance().customTheme(),
data: ThemeController.getInstance().themeChanger(appColors),
child: Navigator(
key: NavigationService.get.navigatorKey,
onGenerateRoute: (settings) => MaterialPageRoute(
Expand Down
6 changes: 5 additions & 1 deletion lib/src/init-main/init.app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void initApp({
required String appName,
required Future<void> Function() loadEnvFile,
required List<ParallelRoute> routes,
required AppColors appColors,
}) async {
try {
// Parallelize initialization tasks using Future.wait
Expand All @@ -57,7 +58,10 @@ void initApp({
}
runApp(ModularApp(
module: AppModule(routes),
child: AppWidget(appName: appName),
child: AppWidget(
appName: appName,
appColors: appColors,
),
));
} catch (error) {
// Handle errors gracefully, you can log the error for debugging
Expand Down
25 changes: 24 additions & 1 deletion lib/src/models/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,43 @@ import 'package:flutter/material.dart';
class User {
String email;
String? name;
String? facilityName;
String? firstName;
String? lastName;
String? middleName;
List<Map<String, dynamic>>? facilities;
String? phone;
User({required this.email, required this.name, this.phone});
User(
{required this.email,
required this.name,
this.phone,
// this.facilities,
this.facilityName,
this.firstName,
this.lastName,
this.middleName});
factory User.fromJson(Map<String, dynamic> json) {
return User(
email: json['email'] as String,
name: json['name'] as String?,
phone: json['phone'] as String?,
// facilities: List<Map<String, dynamic>>.from(json['facilities']),
facilityName: json['facilityName'] as String?,
firstName: json['firstName'] as String?,
middleName: json['middleName'] as String?,
lastName: json['lastName'] as String?,
);
}
Map<String, dynamic> toJson() {
return <String, dynamic>{
'email': email,
'name': name,
'phone': phone,
// 'facilities': facilities,
'facilityName': facilityName,
'firstName': firstName,
'lastName': lastName,
'middleName': middleName,
};
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/service/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class Api {
title: res['message'],
);
}
console('...........................$res');
return res['data'];
} on DioError catch (e) {
if (e.response != null) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/service/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ class AuthServiceController extends GetxController {
required String password,
String? url,
bool showLoading = false}) async {
console('............................................$url');
Map<String, String> credentials = {
'grant_type': 'password',
'username': username,
'password': password
};
// 'Basic ${base64Encode(utf8.encode('${Environment.getInstance().getClientId()}:${Environment.getInstance().getClientSecret()}'))}'

Options requestOptions =
Options(contentType: 'application/x-www-form-urlencoded', headers: {
'Accept': 'application/json',
Expand Down
20 changes: 18 additions & 2 deletions lib/src/service/graphql_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class GraphQLService {
Function(PageableResponse?, bool)? response,
List<OtherParameters>? parameters,
PageableParams pageableParams = const PageableParams(),
bool dontUsePageInPageable = false,
FetchPolicy? fetchPolicy,
required BuildContext context,
}) async {
Expand Down Expand Up @@ -57,10 +58,15 @@ class GraphQLService {
''';
// GraphQLService.getService.endPoint = _endpoint;
// GraphQLService.getService.endPointName = endPointName;
Map<String, dynamic> params = pageableParams.toJson();
if (dontUsePageInPageable) {
params.removeWhere((key, value) => key == 'page');
}
final QueryOptions options = QueryOptions(
operationName: endPointName,
document: gql(endpoint),
variables: {'pageableParam': pageableParams.toJson(), ...otherParams},
// variables: {'pageableParam': usePageableResponse && !SettingsService.use.isEmptyOrNull(pageableResponse) ? pageableResponse!.toMap() : pageableParams.toJson(), ...otherParams},
variables: {'pageableParam': params, ...otherParams},
fetchPolicy: fetchPolicy ?? FetchPolicy.networkOnly,
);

Expand Down Expand Up @@ -381,6 +387,7 @@ class GraphQLService {
required String endPointName,
required String queryFields,
String? successMessage,
String? updateUid,
bool refetchData = false,
required List<InputParameter> inputs,
required BuildContext context,
Expand All @@ -399,7 +406,16 @@ class GraphQLService {
otherParams.addAll(
{element.fieldName: convertListToMap(element.objectValues!)});
} else {
otherParams.addAll({element.fieldName: element.fieldValue});
var dataValues = element.fieldValue;
if (updateUid != null) {
dataValues = {...element.fieldValue, 'uid': updateUid};
}
console('..............xx.........$dataValues');
if (dataValues is Map) {
dataValues.removeWhere((key, value) => key == 'inputType');
}

otherParams.addAll({element.fieldName: dataValues});
}
}
mapVariable =
Expand Down
34 changes: 34 additions & 0 deletions lib/src/service/rest_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:convert';

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

class RestService {
static final Options _requestOptions =
Options(contentType: 'application/x-www-form-urlencoded', headers: {
'Accept': 'application/json',
'Authorization':
'Basic ${base64Encode(utf8.encode('${Environment.getInstance().getClientId()}:${Environment.getInstance().getClientSecret()}'))}'
});
static final Api _api = Api();
static postRequest({required BuildContext context}) async {
Map<String, dynamic> res = await _api.request(context,
type: 'post',
url: '/oauth/token',
options: _requestOptions,
data: {'grant_type': 'client_credentials'});
if (res['access_token'] != null) {
Token token = Token.fromJson(res);
StorageService.setJson('client_token', token.toJson());
return token.accessToken!;
}
}

static getRequest({required BuildContext context}) async {
Map<String, dynamic> res = await _api.request(context,
type: 'post',
url: '/oauth/token',
options: _requestOptions,
data: {'grant_type': 'client_credentials'});
}
}
8 changes: 7 additions & 1 deletion lib/src/service/settings_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:convert';
import 'dart:typed_data';

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

Expand Down Expand Up @@ -284,4 +283,11 @@ class SettingsService {
map.remove(fieldToBeDeleted);
return Map<String, dynamic>.from(map);
}

getSingleValueFromListOfMapByKey(
List<Map<String, dynamic>> listOfMaps, String key) {
var value =
listOfMaps.firstWhereOrNull((map) => map.containsKey(key))?[key];
return value;
}
}
Loading

0 comments on commit 4c1c29d

Please sign in to comment.