Skip to content

Commit

Permalink
copy icon for copying short code
Browse files Browse the repository at this point in the history
  • Loading branch information
RunTerror committed Jun 8, 2024
1 parent 6f50aef commit 626d0b9
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 48 deletions.
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);
}
}
4 changes: 2 additions & 2 deletions lib/Bloc/data/models/beacon/beacon_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/Bloc/data/models/group/group_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:beacon/Bloc/data/models/user/user_model.dart';
import 'package:beacon/Bloc/domain/entities/group/group_entity.dart';
import 'package:hive/hive.dart';
import 'package:json_annotation/json_annotation.dart';

part 'group_model.g.dart';

@HiveType(typeId: 30)
Expand Down
4 changes: 2 additions & 2 deletions lib/Bloc/data/models/group/group_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/Bloc/data/models/user/user_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lib/Bloc/presentation/cubit/group_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:beacon/Bloc/core/constants/location.dart';
import 'package:beacon/Bloc/core/resources/data_state.dart';
import 'package:beacon/Bloc/domain/entities/beacon/beacon_entity.dart';
import 'package:beacon/Bloc/domain/usecase/group_usecase.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:geolocator/geolocator.dart';

abstract class GroupState {}

Expand Down Expand Up @@ -32,6 +34,7 @@ class GroupCubit extends Cubit<GroupState> {
bool isCompletelyFetched = false;
List<BeaconEntity> _beacons = [];
List<BeaconEntity> get beacons => _beacons;
Position? position;

Future<void> createHike(String title, int startsAt, int expiresAt, String lat,
String lon, String groupID) async {
Expand Down Expand Up @@ -89,6 +92,10 @@ class GroupCubit extends Cubit<GroupState> {
}
}

Future<void> fetchPosition() async {
position = await LocationService.getCurrentLocation();
}

clear() {
page = 1;
pageSize = 4;
Expand Down
1 change: 1 addition & 0 deletions lib/Bloc/presentation/screens/group_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _GroupScreenState extends State<GroupScreen>
_scrollController = ScrollController();
_scrollController.addListener(_listener);
_groupCubit = context.read<GroupCubit>();
_groupCubit.position == null ? _groupCubit.fetchPosition() : null;
_groupCubit.fetchGroupHikes(widget.group.id!);
super.initState();
}
Expand Down
21 changes: 18 additions & 3 deletions lib/Bloc/presentation/widgets/create_join_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class CreateJoinGroupDialog {
textCapitalization: TextCapitalization.characters,
style: TextStyle(fontSize: 22.0),
validator: (value) => Validator.validatePasskey(value!),
onChanged: (value) {
_joinGroupController.text = value.toUpperCase();
},
decoration: InputDecoration(
alignLabelWithHint: true,
floatingLabelBehavior: FloatingLabelBehavior.always,
Expand Down Expand Up @@ -392,7 +395,7 @@ class CreateJoinBeaconDialog {
textSize: 18.0,
textColor: Colors.white,
buttonColor: kYellow,
onTap: () {
onTap: () async {
if (_createFormKey.currentState!.validate()) {
DateTime startsAt = DateTime(
startDate!.year,
Expand Down Expand Up @@ -420,9 +423,21 @@ class CreateJoinBeaconDialog {
duration!.inMinutes)
.millisecondsSinceEpoch;

if (groupCubit.position == null) {
utils.showSnackBar(
'Please give access to location!',
context);
groupCubit.fetchPosition();
return;
}
AutoRouter.of(context).maybePop();
groupCubit.createHike(title, startingTime,
endTime, '103', '102', groupID!);
groupCubit.createHike(
title,
startingTime,
endTime,
groupCubit.position!.latitude.toString(),
groupCubit.position!.longitude.toString(),
groupID!);
}
}),
),
Expand Down
6 changes: 0 additions & 6 deletions lib/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

GetIt locator = GetIt.instance;
final UserConfig? userConfig = locator<UserConfig>();
Expand All @@ -43,8 +42,6 @@ final localApi = locator<LocalApi>();
final remoteAuthApi = locator<RemoteAuthApi>();
final remoteHomeApi = locator<RemoteHomeApi>();
final utils = locator<Utils>();
late GraphQLClient gclientAuth;
late GraphQLClient gclientNonAuth;

void setupLocator() async {
// shared prefrence services
Expand Down Expand Up @@ -81,9 +78,6 @@ void setupLocator() async {

final authClient = await graphqlConfig.authClient();

gclientAuth = await graphqlConfig.authClient();
gclientAuth = await graphqlConfig.clientToQuery();

// Remote Api
locator.registerSingleton<RemoteAuthApi>(
RemoteAuthApi(
Expand Down
70 changes: 58 additions & 12 deletions lib/old/components/beacon_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:beacon/old/components/models/beacon/beacon.dart';
import 'package:beacon/old/components/utilities/constants.dart';
import 'package:beacon/router.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import 'package:skeleton_text/skeleton_text.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -144,10 +145,24 @@ class BeaconCustomWidgets {
],
),
),
SizedBox(height: 4.0),
Text('Passkey: ${beacon.shortcode}',
style: Style.commonTextStyle),
SizedBox(height: 4.0),
Row(
children: [
Text('Passkey: ${beacon.shortcode}',
style: Style.commonTextStyle),
IconButton(
onPressed: () {
Clipboard.setData(ClipboardData(
text: beacon.shortcode.toString()));
utils.showSnackBar(
'Shortcode copied!', context);
},
icon: Icon(
Icons.copy,
color: Colors.white,
size: 15,
))
],
),
(beacon.startsAt != null)
? Text(
'Started At: ${DateFormat("hh:mm a, d/M/y").format(DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!)).toString()}',
Expand Down Expand Up @@ -218,14 +233,30 @@ class BeaconCustomWidgets {
// dateTime: DateTime.fromMillisecondsSinceEpoch(
// beacon.startsAt!),
// name: beacon.title,
// beacon: beacon,
// beacon: Beacon(),
// )
],
),
SizedBox(height: 4.0),
Text('Passkey: ${beacon.shortcode}',
style: Style.commonTextStyle),
SizedBox(height: 4.0),
// SizedBox(height: 4.0),
Row(
children: [
Text('Passkey: ${beacon.shortcode}',
style: Style.commonTextStyle),
IconButton(
onPressed: () {
Clipboard.setData(ClipboardData(
text: beacon.shortcode.toString()));
utils.showSnackBar(
'Shortcode copied!', context);
},
icon: Icon(
Icons.copy,
color: Colors.white,
size: 15,
))
],
),
// SizedBox(height: 4.0),
(beacon.startsAt != null)
? Text(
'Starts At: ${DateFormat("hh:mm a, d/M/y").format(DateTime.fromMillisecondsSinceEpoch(beacon.startsAt!)).toString()}',
Expand Down Expand Up @@ -266,9 +297,24 @@ class BeaconCustomWidgets {
],
),
),
SizedBox(height: 4.0),
Text('Passkey: ${beacon.shortcode}',
style: Style.commonTextStyle),
Row(
children: [
Text('Passkey: ${beacon.shortcode}',
style: Style.commonTextStyle),
IconButton(
onPressed: () {
Clipboard.setData(ClipboardData(
text: beacon.shortcode.toString()));
utils.showSnackBar(
'Shortcode copied!', context);
},
icon: Icon(
Icons.copy,
color: Colors.white,
size: 15,
))
],
),
SizedBox(height: 4.0),
(beacon.startsAt != null)
? Text(
Expand Down
22 changes: 19 additions & 3 deletions lib/old/components/group_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:beacon/locator.dart';
import 'package:beacon/old/components/utilities/constants.dart';
import 'package:beacon/router.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import 'package:skeleton_text/skeleton_text.dart';
import 'models/group/group.dart';
Expand Down Expand Up @@ -74,9 +75,24 @@ class GroupCustomWidgets {
'Group has $noBeacons beacons ',
style: Style.commonTextStyle,
),
SizedBox(height: 4.0),
Text('Passkey: ${group.shortcode}',
style: Style.commonTextStyle),
// SizedBox(height: 4.0),
Row(
children: [
Text('Passkey: ${group.shortcode}',
style: Style.commonTextStyle),
IconButton(
onPressed: () {
Clipboard.setData(
ClipboardData(text: group.shortcode.toString()));
utils.showSnackBar('Shortcode copied!', context);
},
icon: Icon(
Icons.copy,
color: Colors.white,
size: 15,
))
],
)
],
),
],
Expand Down
Loading

0 comments on commit 626d0b9

Please sign in to comment.