Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth home and cubit module migration #238

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
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
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 All @@ -22,17 +20,17 @@ class GraphQLConfig {
));

Future getToken() async {
final _token = userConfig!.currentUser!.authToken;
token = _token;
await localApi.init();
final user = await localApi.fetchUser();
if (user != null) {
token = user.authToken;
}
return true;
}

GraphQLClient clientToQuery() {
log(httpLink.toString());
log(EnvironmentConfig.httpEndpoint!);
return GraphQLClient(
cache: GraphQLCache(),
// cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
link: httpLink,
);
}
Expand All @@ -49,7 +47,7 @@ class GraphQLConfig {

GraphQLClient graphQlClient() {
return GraphQLClient(
cache: GraphQLCache(),
cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
link: Link.split(
(request) => request.isSubscription,
websocketLink,
Expand Down
12 changes: 12 additions & 0 deletions lib/Bloc/config/user_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:beacon/Bloc/data/models/user/user_model.dart';
import 'package:beacon/locator.dart';

class UserModelConfig {
UserModel _userModel = UserModel(authToken: 'null');
UserModel get userModel => _userModel;

Future<bool> updateUser(UserModel updateUserDetails) async {
_userModel = updateUserDetails;
return localApi.saveUser(updateUserDetails);
}
}
30 changes: 30 additions & 0 deletions lib/Bloc/core/constants/location.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:geolocator/geolocator.dart';

class LocationService {
static Future<Position> getCurrentLocation() async {
bool serviceEnabled;
LocationPermission permission;

serviceEnabled = await Geolocator.isLocationServiceEnabled();

if (!serviceEnabled) {
return Future.error('Location service is disabled.');
}

permission = await Geolocator.checkPermission();

if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Location permission is denied');
}
}

if (permission == LocationPermission.deniedForever) {
return Future.error('Location permission is permanently denied.');
}

return await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
}
}
32 changes: 0 additions & 32 deletions lib/queries/auth.dart → lib/Bloc/core/queries/auth.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:developer';

class AuthQueries {
String registerUser(String? name, String email, String? password) {
return '''
Expand Down Expand Up @@ -43,7 +41,6 @@ class AuthQueries {
}

String fetchUserInfo() {
log('fetching user info');
return '''
query{
me{
Expand All @@ -52,38 +49,9 @@ class AuthQueries {
name
groups{
_id
title
shortcode
leader {
_id
name
}
members {
_id
name
}
beacons{
_id
}
}
beacons{
_id
title
shortcode
leader {
_id
name
}
followers{
_id
name
}
location {
lat
lon
}
startsAt
expiresAt
}
}
}
Expand Down
File renamed without changes.
53 changes: 53 additions & 0 deletions lib/queries/group.dart → lib/Bloc/core/queries/group.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
import 'package:graphql_flutter/graphql_flutter.dart';

class GroupQueries {
String fetchUserGroups(int page, int pageSize) {
return '''
query {
groups(page: $page, pageSize: $pageSize) {
_id
title
shortcode
leader {
_id
name
}
members {
_id
name
}
beacons {
_id
}
}
}
''';
}

String createGroup(String? title) {
return '''
mutation{
Expand Down Expand Up @@ -129,6 +152,36 @@ class GroupQueries {
''';
}

String fetchHikes(String groupID, int page, int pageSize) {
return '''
query{
beacons(groupId: "$groupID", page: $page, pageSize: $pageSize){
_id
title
shortcode
leader {
_id
name
}
location{
lat
lon
}
followers {
_id
name
}
group{
_id
}
startsAt
expiresAt

}
}
''';
}

final groupJoinedSubGql = gql(r'''
subscription StreamNewlyJoinedGroups($id: ID!){
groupJoined(id: $id){
Expand Down
14 changes: 14 additions & 0 deletions lib/Bloc/core/resources/data_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
abstract class DataState<T> {
final T? data;
final String? 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(String 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 SharedPreferenceService {
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);
}
Loading
Loading