Skip to content

Commit

Permalink
Merge pull request #235 from RunTerror/main
Browse files Browse the repository at this point in the history
Folder structuring
  • Loading branch information
Akshatji800 authored Sep 28, 2024
2 parents 712acae + 6ab45ac commit 72c1c09
Show file tree
Hide file tree
Showing 67 changed files with 709 additions and 254 deletions.
1 change: 0 additions & 1 deletion .fvm/flutter_sdk

This file was deleted.

3 changes: 0 additions & 3 deletions .fvmrc

This file was deleted.

4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
arguments=--init-script /var/folders/87/sjnhgg2s1dn1b0l2r0jrgxx80000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/87/sjnhgg2s1dn1b0l2r0jrgxx80000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle
auto.sync=true
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home
java.home=/opt/homebrew/Cellar/openjdk/21.0.2/libexec/openjdk.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:developer';

import 'package:beacon/config/environment_config.dart';
import 'package:beacon/Bloc/config/enviornment_config.dart';
import 'package:beacon/locator.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

Expand Down Expand Up @@ -28,8 +26,6 @@ class GraphQLConfig {
}

GraphQLClient clientToQuery() {
log(httpLink.toString());
log(EnvironmentConfig.httpEndpoint!);
return GraphQLClient(
cache: GraphQLCache(),
// cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions lib/Bloc/core/resources/data_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:graphql/client.dart';

abstract class DataState<T> {
final T? data;
final OperationException? error;

const DataState({this.data, this.error});
}

class DataSuccess<T> extends DataState<T> {
const DataSuccess(T data) : super(data: data);
}

class DataFailed<T> extends DataState<T> {
const DataFailed(OperationException error) : super(error: error);
}
40 changes: 40 additions & 0 deletions lib/Bloc/core/services/shared_prefrence_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesService {
SharedPreferenceService() {
init();
}

late SharedPreferences _prefs;

init() async {
_prefs = await SharedPreferences.getInstance();
}

Future<void> saveData(String key, dynamic value) async {
try {
if (value is String) {
await _prefs.setString(key, value);
} else if (value is int) {
await _prefs.setInt(key, value);
} else if (value is bool) {
await _prefs.setBool(key, value);
} else if (value is double) {
await _prefs.setDouble(key, value);
} else if (value is List<String>) {
await _prefs.setStringList(key, value);
}
} catch (e) {
debugPrint(e.toString());
}
}

Future<dynamic> loadData(String key) async {
return _prefs.get(key);
}

Future deleteData(String key) async {
return await _prefs.remove('key');
}
}
32 changes: 32 additions & 0 deletions lib/Bloc/core/services/size_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';

class SizeConfig {
static late MediaQueryData _mediaQueryData;
static late double screenWidth;
static late double screenHeight;
static double? blockSizeHorizontal;
static double? blockSizeVertical;
static double? paddingTop;

static late double _safeAreaHorizontal;
static late double _safeAreaVertical;
static double? safeBlockHorizontal;
static double? safeBlockVertical;

void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
blockSizeHorizontal = screenWidth / 100;
blockSizeVertical = screenHeight / 100;

_safeAreaHorizontal =
_mediaQueryData.padding.left + _mediaQueryData.padding.right;
_safeAreaVertical =
_mediaQueryData.padding.top + _mediaQueryData.padding.bottom;
safeBlockHorizontal = (screenWidth - _safeAreaHorizontal) / 100;
safeBlockVertical = (screenHeight - _safeAreaVertical) / 100;
debugPrint("safeBlockHorizontal: $safeBlockHorizontal");
debugPrint("safeBlockVertical: $safeBlockVertical");
}
}
3 changes: 3 additions & 0 deletions lib/Bloc/core/usercase/usecase.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class UseCase<Type, Paramas> {
Future<Type> call(Paramas paramas);
}
78 changes: 78 additions & 0 deletions lib/Bloc/core/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'dart:developer';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:graphql/client.dart';

class Utils {
void showSnackBar(String message, BuildContext context,
{Duration duration = const Duration(seconds: 2)}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: duration,
content: Text(
message,
style: TextStyle(color: Colors.black),
),
// backgroundColor: kLightBlue.withOpacity(0.8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
behavior: SnackBarBehavior.floating,
elevation: 5,
),
);
}

String filterException(OperationException exception) {
// checking grapqhl exceptions
if (exception.graphqlErrors.isNotEmpty) {
return exception.graphqlErrors.first.message;
}
// checking link exception
else if (exception.linkException != null) {
log('Link Exception: ${exception.linkException!.originalStackTrace}');
return 'Server exception';
} else {
return 'Network Error: The request could not be completed.';
}
}

Future<bool> checkInternetConnectivity() async {
final connectivityResult = await (Connectivity().checkConnectivity());

if (connectivityResult == ConnectivityResult.mobile ||
connectivityResult == ConnectivityResult.wifi ||
connectivityResult == ConnectivityResult.ethernet) {
return true;
}
return false;
}

String? validateEmail(String? value) {
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
if (value == null || value.isEmpty) {
return 'Email address is required';
} else if (!emailRegex.hasMatch(value)) {
return 'Enter a valid email address';
}
return null; // Return null if the email is valid
}

String? validatePassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password is required';
} else if (value.length < 8) {
return '8-digit password is required';
}
return null;
}

String? validateName(String? value) {
if (value == null || value.isEmpty) {
return 'Name is required';
}
return null;
}
}
46 changes: 46 additions & 0 deletions lib/Bloc/theme/theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';

class CustomTheme {
static const String _fontFamily =
'FuturaBold'; // Match the name in pubspec.yaml

// Define your custom colors
Color kYellow = Color(0xFFFDBB2C);
Color kBlue = Color(0xFF222375);
Color lightkBlue = Color(0xFF535393);
Color kLightBlue = Color(0xFFE8F1F8);
Color kBlack = Color(0xFF343434);
Color shimmerSkeletonColor = Color(0xff4e4f91);
Color hintColor = Colors.black54;

// Define your custom theme data
ThemeData myTheme = ThemeData(
fontFamily: _fontFamily,
// Define primary colors
primaryColor: const Color(0xFF222375),
hintColor: const Color.fromARGB(255, 105, 103, 103),

// Define text themes
textTheme: const TextTheme(
displayLarge: TextStyle(
fontSize: 19,
fontWeight: FontWeight.bold,
fontFamily: _fontFamily,
color: Colors.white,
),
displayMedium: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w800,
fontFamily: _fontFamily,
color: Colors.black,
),
bodyLarge: TextStyle(
fontSize: 16,
fontFamily: _fontFamily,
color: Colors.white,
),
),

// Define other theme properties such as fonts, buttons, etc.
);
}
27 changes: 16 additions & 11 deletions lib/locator.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'package:beacon/main.dart';
import 'package:beacon/services/connection_checker.dart';
import 'package:beacon/services/database_mutation_functions.dart';
import 'package:beacon/services/graphql_config.dart';
import 'package:beacon/services/hive_localdb.dart';
import 'package:beacon/services/local_notification.dart';
import 'package:beacon/services/navigation_service.dart';
import 'package:beacon/services/user_config.dart';
import 'package:beacon/view_model/auth_screen_model.dart';
import 'package:beacon/view_model/home_screen_view_model.dart';
import 'package:beacon/view_model/hike_screen_model.dart';
import 'package:beacon/view_model/group_screen_view_model.dart';
import 'package:beacon/old/components/services/connection_checker.dart';
import 'package:beacon/old/components/services/database_mutation_functions.dart';
import 'package:beacon/Bloc/config/graphql_config.dart';
import 'package:beacon/old/components/services/hive_localdb.dart';
import 'package:beacon/old/components/services/local_notification.dart';
import 'package:beacon/old/components/services/navigation_service.dart';
import 'package:beacon/old/components/services/shared_preference_service.dart';
import 'package:beacon/old/components/services/user_config.dart';
import 'package:beacon/old/components/view_model/auth_screen_model.dart';
import 'package:beacon/old/components/view_model/home_screen_view_model.dart';
import 'package:beacon/old/components/view_model/hike_screen_model.dart';
import 'package:beacon/old/components/view_model/group_screen_view_model.dart';
import 'package:get_it/get_it.dart';

GetIt locator = GetIt.instance;
Expand All @@ -21,8 +22,12 @@ final GraphQLConfig? graphqlConfig = locator<GraphQLConfig>();
final LocalNotification? localNotif = locator<LocalNotification>();
final HiveLocalDb? hiveDb = locator<HiveLocalDb>();
final ConnectionChecker? connectionChecker = locator<ConnectionChecker>();
final sharedPrefrenceService = locator<SharedPreferenceService>();

void setupLocator() {
// shared prefrence services
locator.registerSingleton(SharedPreferenceService());

//services
locator.registerSingleton(NavigationService());

Expand Down
7 changes: 4 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:beacon/config/environment_config.dart';
import 'package:beacon/Bloc/config/enviornment_config.dart';
import 'package:beacon/locator.dart';
import 'package:beacon/router.dart' as router;
import 'package:beacon/view_model/base_view_model.dart';
import 'package:beacon/views/base_view.dart';
import 'package:beacon/old/components/view_model/base_view_model.dart';
import 'package:beacon/old/components/views/base_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
Expand All @@ -16,6 +16,7 @@ void main() async {
DeviceOrientation.portraitDown,
]);
setupLocator();

await localNotif!.initialize();
await hiveDb!.init();
runApp(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:beacon/components/active_beacon.dart';
import 'package:beacon/components/timer.dart';
import 'package:beacon/old/components/active_beacon.dart';
import 'package:beacon/old/components/timer.dart';
import 'package:beacon/locator.dart';
import 'package:beacon/models/beacon/beacon.dart';
import 'package:beacon/utilities/constants.dart';
import 'package:beacon/views/hike_screen.dart';
import 'package:beacon/old/components/models/beacon/beacon.dart';
import 'package:beacon/old/components/utilities/constants.dart';
import 'package:beacon/old/components/views/hike_screen.dart';
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import 'package:skeleton_text/skeleton_text.dart';
Expand Down Expand Up @@ -32,9 +32,9 @@ class BeaconCustomWidgets {
}
}
if (!hasStarted) {
navigationService!.showSnackBar(
'Beacon has not yet started! \nPlease come back at ${DateFormat("hh:mm a, d/M/y").format(DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!)).toString()}',
);
// navigationService!.showSnackBar(
// 'Beacon has not yet started! \nPlease come back at ${DateFormat("hh:mm a, d/M/y").format(DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!)).toString()}',
// );
return;
}
if (hasStarted &&
Expand All @@ -49,9 +49,9 @@ class BeaconCustomWidgets {
final Beacon? _beacon =
await databaseFunctions!.joinBeacon(beacon.shortcode);
if (!hasStarted) {
navigationService!.showSnackBar(
'Beacon has not yet started! \nPlease come back at ${DateFormat("hh:mm a, d/M/y").format(DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!)).toString()}',
);
// navigationService!.showSnackBar(
// 'Beacon has not yet started! \nPlease come back at ${DateFormat("hh:mm a, d/M/y").format(DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!)).toString()}',
// );
return;
}
if (hasStarted && _beacon != null) {
Expand Down
Loading

0 comments on commit 72c1c09

Please sign in to comment.