Skip to content

Commit

Permalink
refactor: Improve code layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Aug 29, 2023
1 parent 7e51d3c commit 445013d
Show file tree
Hide file tree
Showing 37 changed files with 314 additions and 314 deletions.
3 changes: 2 additions & 1 deletion lib/screens/CheckLocationScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import 'package:locus/services/settings_service.dart';
import 'package:locus/utils/helper_sheet.dart';
import 'package:locus/utils/load_status.dart';
import 'package:locus/utils/location/index.dart';
import 'package:locus/utils/show_message.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/utils/ui-message/enums.dart';
import 'package:locus/utils/ui-message/show-message.dart';
import 'package:locus/widgets/RequestLocationPermissionMixin.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:lottie/lottie.dart';
Expand Down
7 changes: 4 additions & 3 deletions lib/screens/LocationsOverviewScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import 'package:locus/screens/locations_overview_screen_widgets/ViewLocationPopu
import 'package:locus/screens/locations_overview_screen_widgets/view_location_fetcher.dart';
import 'package:locus/services/task_service.dart';
import 'package:locus/services/view_service.dart';
import 'package:locus/utils/helpers.dart';
import 'package:locus/utils/location/get-fallback-location.dart';
import 'package:locus/utils/location/index.dart';
import 'package:locus/utils/navigation.dart';
import 'package:locus/utils/show_message.dart';
import 'package:locus/utils/permissions/has-granted.dart';
import 'package:locus/utils/permissions/request.dart';
import 'package:locus/utils/ui-message/enums.dart';
import 'package:locus/utils/ui-message/show-message.dart';
import 'package:locus/widgets/FABOpenContainer.dart';
import 'package:locus/widgets/LocationsMap.dart';
import 'package:locus/widgets/LocusFlutterMap.dart';
Expand All @@ -54,7 +56,6 @@ import '../services/manager_service.dart';
import '../services/settings_service.dart';
import '../utils/PageRoute.dart';
import '../utils/color.dart';
import '../utils/permission.dart';
import '../utils/platform.dart';
import '../utils/theme.dart';
import 'ViewDetailScreen.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/SettingsScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import 'package:locus/screens/settings_screen_widgets/TransferSenderScreen.dart'
import 'package:locus/services/task_service.dart';
import 'package:locus/utils/PageRoute.dart';
import 'package:locus/utils/import_export_handler.dart';
import 'package:locus/utils/show_message.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/utils/ui-message/enums.dart';
import 'package:locus/utils/ui-message/show-message.dart';
import 'package:locus/widgets/Paper.dart';
import 'package:locus/widgets/PlatformFlavorWidget.dart';
import 'package:locus/widgets/SettingsCaretIcon.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/ViewDetailScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'package:locus/services/location_alarm_service.dart';
import 'package:locus/services/view_service.dart';
import 'package:locus/utils/PageRoute.dart';
import 'package:locus/utils/bunny.dart';
import 'package:locus/utils/permissions/has-granted.dart';
import 'package:locus/utils/permissions/request.dart';
import 'package:locus/widgets/EmptyLocationsThresholdScreen.dart';
import 'package:locus/widgets/FillUpPaint.dart';
import 'package:locus/widgets/LocationFetchEmpty.dart';
Expand All @@ -26,7 +28,6 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import '../constants/spacing.dart';
import '../services/location_fetch_controller.dart';
import '../services/location_point_service.dart';
import '../utils/permission.dart';
import '../utils/theme.dart';
import '../widgets/LocationFetchError.dart';
import '../widgets/LocationStillFetchingBanner.dart';
Expand Down
17 changes: 11 additions & 6 deletions lib/screens/import_task_sheet_widgets/ReceiveViewByBluetooth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:locus/constants/spacing.dart';
import 'package:locus/constants/values.dart';
import 'package:locus/extensions/string.dart';
import 'package:locus/utils/bluetooth.dart';
import 'package:locus/utils/permissions/mixins.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/widgets/BluetoothPermissionRequiredScreen.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand All @@ -29,7 +29,8 @@ class ReceiveViewByBluetooth extends StatefulWidget {
State<ReceiveViewByBluetooth> createState() => _ReceiveViewByBluetoothState();
}

class _ReceiveViewByBluetoothState extends State<ReceiveViewByBluetooth> with BluetoothPermissionMixin {
class _ReceiveViewByBluetoothState extends State<ReceiveViewByBluetooth>
with BluetoothPermissionMixin {
final String id = createIdentifier();
String? connectionID;

Expand Down Expand Up @@ -80,14 +81,16 @@ class _ReceiveViewByBluetoothState extends State<ReceiveViewByBluetooth> with Bl
barrierDismissible: false,
builder: (context) => PlatformAlertDialog(
title: Text(l10n.importTask_bluetooth_receive_request_title),
content: Text(l10n.importTask_bluetooth_receive_request_description),
content:
Text(l10n.importTask_bluetooth_receive_request_description),
actions: [
PlatformDialogAction(
onPressed: () => Navigator.of(context).pop(false),
material: (_, __) => MaterialDialogActionData(
icon: const Icon(Icons.close),
),
child: Text(l10n.importTask_bluetooth_receive_request_decline),
child:
Text(l10n.importTask_bluetooth_receive_request_decline),
),
PlatformDialogAction(
onPressed: () => Navigator.of(context).pop(true),
Expand All @@ -111,7 +114,8 @@ class _ReceiveViewByBluetoothState extends State<ReceiveViewByBluetooth> with Bl
final rawData = const Utf8Decoder().convert(payload.bytes!);
final view = TaskView.fromJSON(jsonDecode(rawData));

await Nearby().sendBytesPayload(endPointID, TRANSFER_SUCCESS_MESSAGE);
await Nearby()
.sendBytesPayload(endPointID, TRANSFER_SUCCESS_MESSAGE);

widget.onImport(view);
},
Expand Down Expand Up @@ -141,7 +145,8 @@ class _ReceiveViewByBluetoothState extends State<ReceiveViewByBluetooth> with Bl
final l10n = AppLocalizations.of(context);

if (!hasGrantedBluetoothPermission) {
return BluetoothPermissionRequiredScreen(onRequest: checkBluetoothPermission);
return BluetoothPermissionRequiredScreen(
onRequest: checkBluetoothPermission);
}

if (connectionID == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import 'package:intl/intl.dart';
import 'package:locus/constants/values.dart';
import 'package:locus/services/timers_service.dart';
import 'package:locus/utils/date.dart';
import 'package:locus/utils/show_message.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/utils/ui-message/enums.dart';
import 'package:locus/utils/ui-message/show-message.dart';
import 'package:locus/widgets/ModalSheet.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:locus/widgets/ModalSheetContent.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import 'package:locus/utils/navigation.dart';
import 'package:latlong2/latlong.dart';

import 'package:locus/utils/location/index.dart';
import 'package:locus/utils/permissions/has-granted.dart';
import 'package:locus/utils/permissions/request.dart';
import '../../constants/spacing.dart';
import '../../services/location_point_service.dart';
import '../../utils/icon.dart';
import '../../utils/permission.dart';
import '../../utils/theme.dart';
import '../../widgets/BentoGridElement.dart';
import '../../widgets/LocusFlutterMap.dart';
Expand Down
8 changes: 5 additions & 3 deletions lib/screens/settings_screen_widgets/TransferSenderScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:locus/constants/spacing.dart';
import 'package:locus/constants/values.dart';
import 'package:locus/services/settings_service.dart';
import 'package:locus/services/task_service.dart';
import 'package:locus/utils/bluetooth.dart';
import 'package:locus/utils/import_export_handler.dart';
import 'package:locus/utils/permissions/mixins.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/widgets/BluetoothPermissionRequiredScreen.dart';
import 'package:locus/widgets/PINView.dart';
Expand All @@ -29,7 +29,8 @@ class TransferSenderScreen extends StatefulWidget {
State<TransferSenderScreen> createState() => _TransferSenderScreenState();
}

class _TransferSenderScreenState extends State<TransferSenderScreen> with BluetoothPermissionMixin {
class _TransferSenderScreenState extends State<TransferSenderScreen>
with BluetoothPermissionMixin {
final pin = Random().nextInt(90000) + 10000;
String? connectionID;
bool connectionEstablished = false;
Expand Down Expand Up @@ -147,7 +148,8 @@ class _TransferSenderScreenState extends State<TransferSenderScreen> with Blueto
child: Center(
child: (() {
if (!hasGrantedBluetoothPermission) {
return BluetoothPermissionRequiredScreen(onRequest: checkBluetoothPermission);
return BluetoothPermissionRequiredScreen(
onRequest: checkBluetoothPermission);
}

if (connectionEstablished) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'
import 'package:locus/constants/spacing.dart';
import 'package:locus/services/location_point_service.dart';
import 'package:locus/utils/icon.dart';
import 'package:locus/utils/show_message.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/utils/ui-message/show-message.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:provider/provider.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:locus/constants/spacing.dart';
import 'package:locus/constants/values.dart';
import 'package:locus/models/log.dart';
import 'package:locus/utils/bluetooth.dart';
import 'package:locus/utils/import_export_handler.dart';
import 'package:locus/utils/permissions/mixins.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/widgets/BluetoothPermissionRequiredScreen.dart';
import 'package:lottie/lottie.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import 'package:locus/services/settings_service.dart';
import 'package:locus/utils/helper_sheet.dart';
import 'package:locus/utils/location/get-fallback-location.dart';
import 'package:locus/utils/location/index.dart';
import 'package:locus/utils/permission.dart';
import 'package:locus/utils/permissions/has-granted.dart';
import 'package:locus/utils/permissions/request.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/widgets/LocationsMap.dart';
import 'package:locus/widgets/RequestNotificationPermissionMixin.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:locus/constants/spacing.dart';
import 'package:locus/utils/bluetooth.dart';
import 'package:locus/utils/permissions/has-granted.dart';
import 'package:locus/utils/permissions/mixins.dart';
import 'package:locus/utils/theme.dart';
import 'package:locus/widgets/PINView.dart';
import 'package:lottie/lottie.dart';
Expand Down Expand Up @@ -57,7 +58,7 @@ class _TransferReceiverScreenState extends State<TransferReceiverScreen>
startAdvertising() async {
final serviceID = await getBluetoothServiceID();

final hasGranted = await checkIfHasBluetoothPermission();
final hasGranted = await hasGrantedAllBluetoothPermissions();

if (!hasGranted) {
return;
Expand Down Expand Up @@ -94,8 +95,8 @@ class _TransferReceiverScreenState extends State<TransferReceiverScreen>
Nearby().acceptConnection(
connectionID!,
onPayLoadRecieved: (_, payload) async {
await Nearby().sendBytesPayload(
connectionID!, TRANSFER_SUCCESS_MESSAGE);
await Nearby()
.sendBytesPayload(connectionID!, TRANSFER_SUCCESS_MESSAGE);

widget.onContentReceived(
const Utf8Decoder().convert(payload.bytes!),
Expand Down
27 changes: 13 additions & 14 deletions lib/services/location_point_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import 'package:battery_plus/battery_plus.dart';
import 'package:cryptography/cryptography.dart';
import 'package:flutter/services.dart';
import 'package:geolocator/geolocator.dart';
import 'package:locus/utils/cryptography/decrypt.dart';
import 'package:uuid/uuid.dart';

import '../utils/cryptography.dart';

const uuid = Uuid();

class LocationPointService {
Expand Down Expand Up @@ -40,8 +39,7 @@ class LocationPointService {
double? batteryLevel,
this.isCopy = false,
this.batteryState,
})
: altitude = altitude == 0.0 ? null : altitude,
}) : altitude = altitude == 0.0 ? null : altitude,
speed = speed == 0.0 ? null : speed,
speedAccuracy = speedAccuracy == 0.0 ? null : speedAccuracy,
heading = heading == 0.0 ? null : heading,
Expand All @@ -52,7 +50,7 @@ class LocationPointService {
"${latitude.toStringAsFixed(5)}, ${longitude.toStringAsFixed(5)}";

factory LocationPointService.dummyFromLatLng(final LatLng latLng,
{final double accuracy = 10.0}) =>
{final double accuracy = 10.0}) =>
LocationPointService(
id: uuid.v4(),
createdAt: DateTime.now(),
Expand All @@ -77,8 +75,8 @@ class LocationPointService {
batteryState: json["batteryState"] == null
? null
: BatteryState.values.firstWhere(
(value) => value.name == json["batteryState"],
),
(value) => value.name == json["batteryState"],
),
);
}

Expand All @@ -100,7 +98,8 @@ class LocationPointService {
}

static Future<LocationPointService> fromPosition(
final Position position,) async {
final Position position,
) async {
double? batteryLevel;
BatteryState? batteryState;

Expand Down Expand Up @@ -134,8 +133,7 @@ class LocationPointService {

/// Copies `current` with a new id - mainly used in conjunction with `createUsingCurrentLocation`
/// in background fetch to avoid fetching the location multiple times.
LocationPointService copyWithDifferentId() =>
LocationPointService(
LocationPointService copyWithDifferentId() => LocationPointService(
id: uuid.v4(),
createdAt: DateTime.now(),
latitude: latitude,
Expand All @@ -149,8 +147,10 @@ class LocationPointService {
batteryState: batteryState,
);

static Future<LocationPointService> fromEncrypted(final String cipherText,
final SecretKey encryptionPassword,) async {
static Future<LocationPointService> fromEncrypted(
final String cipherText,
final SecretKey encryptionPassword,
) async {
final message = await decryptUsingAES(
cipherText,
encryptionPassword,
Expand All @@ -159,8 +159,7 @@ class LocationPointService {
return LocationPointService.fromJSON(jsonDecode(message));
}

Position asPosition() =>
Position(
Position asPosition() => Position(
latitude: latitude,
longitude: longitude,
altitude: altitude ?? 0.0,
Expand Down
3 changes: 2 additions & 1 deletion lib/services/task_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'package:locus/constants/values.dart';
import 'package:locus/models/log.dart';
import 'package:locus/services/location_base.dart';
import 'package:locus/services/log_service.dart';
import 'package:locus/utils/cryptography.dart';
import 'package:locus/utils/cryptography/encrypt.dart';
import 'package:locus/utils/cryptography/utils.dart';
import 'package:locus/utils/location/index.dart';
import 'package:nostr/nostr.dart';
import 'package:uuid/uuid.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/services/view_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter_logs/flutter_logs.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:locus/api/nostr-fetch.dart';
import 'package:locus/services/task_service.dart';
import 'package:locus/utils/cryptography.dart';
import 'package:locus/utils/cryptography/decrypt.dart';
import 'package:nostr/nostr.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down
Loading

0 comments on commit 445013d

Please sign in to comment.