Skip to content

Commit

Permalink
Merge pull request #4 from synyx/flutter_3_10
Browse files Browse the repository at this point in the history
Flutter 3.10
  • Loading branch information
enoy19 authored May 22, 2023
2 parents b1a8b03 + e230cf2 commit 6c74d77
Show file tree
Hide file tree
Showing 48 changed files with 403 additions and 386 deletions.
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
{
"label": "gen:build_runner",
"type": "shell",
"command": "flutter pub run build_runner build --delete-conflicting-outputs",
"command": "dart run build_runner build --delete-conflicting-outputs",
"problemMatcher": []
},
{
"label": "gen:build_runner:watch",
"type": "shell",
"command": "flutter pub run build_runner watch --delete-conflicting-outputs",
"command": "dart run build_runner watch --delete-conflicting-outputs",
"problemMatcher": []
},
]
Expand Down
2 changes: 1 addition & 1 deletion lib/cubit/booking_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syntrack/cubit/time_entries_cubit.dart';
import 'package:syntrack/exception/work_interface_not_found.dart';
import 'package:syntrack/model/common/time_entry.dart';
Expand Down
13 changes: 7 additions & 6 deletions lib/cubit/task_search_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'dart:async';

import 'package:bloc/bloc.dart';

import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:just_debounce_it/just_debounce_it.dart';
import 'package:meta/meta.dart';
import 'package:syntrack/model/common/task_search_result.dart';
import 'package:syntrack/repository/work_repository.dart';

Expand All @@ -13,7 +14,7 @@ class TaskSearchCubit extends Cubit<TaskSearchState> {
final WorkRepository workRepository;
String _prevQuery = '';

TaskSearchCubit(this.workRepository) : super(Done(const []));
TaskSearchCubit(this.workRepository) : super(const Done([]));

Future<void> searchWithDebounce(String query) async {
if (query == _prevQuery) {
Expand All @@ -22,12 +23,12 @@ class TaskSearchCubit extends Cubit<TaskSearchState> {

_prevQuery = query;

emit(Searching([]));
emit(const Searching([]));
Debounce.milliseconds(1000, search, [query]);
}

Future<Done> search(String query) async {
emit(Searching([]));
emit(const Searching([]));

final searchStream = workRepository.search(query);
await searchStream.forEach((element) {
Expand All @@ -40,7 +41,7 @@ class TaskSearchCubit extends Cubit<TaskSearchState> {
}

Stream<TaskSearchResult> searchStream(String query) async* {
emit(Searching([]));
emit(const Searching([]));

await for (final searchResult in workRepository.search(query)) {
emit(Searching([...state.results, searchResult]));
Expand Down
6 changes: 3 additions & 3 deletions lib/cubit/task_search_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ part of 'task_search_cubit.dart';
abstract class TaskSearchState extends Equatable {
final List<TaskSearchResult> results;

TaskSearchState(this.results);
const TaskSearchState(this.results);

@override
List<Object?> get props => [results];
}

class Searching extends TaskSearchState {
Searching(List<TaskSearchResult> results) : super(results);
const Searching(List<TaskSearchResult> results) : super(results);
}

class Done extends TaskSearchState {
Done(List<TaskSearchResult> results) : super(results);
const Done(List<TaskSearchResult> results) : super(results);
}
6 changes: 3 additions & 3 deletions lib/cubit/time_entries_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:uuid/uuid.dart';
class TimeEntriesCubit extends HydratedCubit<List<TimeEntry>> {
TimeEntriesCubit() : super([]);

final uuid = Uuid();
final uuid = const Uuid();

void newTrackedTimeEntry({
required Task? task,
Expand Down Expand Up @@ -57,14 +57,14 @@ class TimeEntriesCubit extends HydratedCubit<List<TimeEntry>> {
void copyToNextDay(TimeEntry entry) {
copyTo(
entry,
(entry) => [entry.start.add(Duration(days: 1))],
(entry) => [entry.start.add(const Duration(days: 1))],
);
}

void copyToPreviousDay(TimeEntry entry) {
copyTo(
entry,
(entry) => [entry.start.subtract(Duration(days: 1))],
(entry) => [entry.start.subtract(const Duration(days: 1))],
);
}

Expand Down
7 changes: 2 additions & 5 deletions lib/cubit/time_tracking_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ class TimeTrackingCubit extends HydratedCubit<TimeTrackingState> {
try {
return TimeTrackingState.fromJson(jsonEncode(json));
} catch (e) {
print(e);
debugPrint(e.toString());
return TimeTrackingState.idle();
}
}

@override
Map<String, dynamic>? toJson(TimeTrackingState state) {
if (state is TimeTrackingState) {
return jsonDecode(state.toJson());
}
return <String, dynamic>{};
return jsonDecode(state.toJson());
}
}
17 changes: 10 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import 'package:syntrack/cubit/time_tracking_cubit.dart';
import 'package:syntrack/cubit/work_interface_cubit.dart';
import 'package:syntrack/repository/data/latest_bookings_data_provider.dart';
import 'package:syntrack/repository/work_repository.dart';
import 'package:syntrack/router.gr.dart';
import 'package:path/path.dart';
import 'package:syntrack/router.dart';
import 'package:path/path.dart' as path;

void main() async {
WidgetsFlutterBinding.ensureInitialized();
final documentsDir = await getApplicationDocumentsDirectory();
final appDirName = kDebugMode ? 'synTrack_dev' : 'synTrack';
const appDirName = kDebugMode ? 'synTrack_dev' : 'synTrack';
final appDir = await Directory('${documentsDir.absolute.path}/$appDirName').create();

await createHydratedBoxBackup(appDir);
Expand All @@ -41,7 +41,7 @@ Future<void> createHydratedBoxBackup(Directory appDir, {int maxBackups = 10}) as
.list(followLinks: false, recursive: false)
.where((file) {
final stat = file.statSync();
final fileName = basename(file.path);
final fileName = path.basename(file.path);
return stat.type == FileSystemEntityType.file && fileName.startsWith("backup_");
})
.map((file) => File(file.path))
Expand All @@ -59,9 +59,11 @@ Future<void> createHydratedBoxBackup(Directory appDir, {int maxBackups = 10}) as
}

class SynTrack extends StatelessWidget {
static final primarySwatch = Colors.blue;
static const primarySwatch = Colors.blue;
final _appRouter = AppRouter();

SynTrack({super.key});

@override
Widget build(BuildContext context) {
return RepositoryProvider(
Expand Down Expand Up @@ -102,15 +104,16 @@ class SynTrack extends StatelessWidget {
child: Sizer(
builder: (context, orientation, deviceType) {
return MaterialApp.router(
supportedLocales: [Locale('de')],
localizationsDelegates: [
supportedLocales: const [Locale('de')],
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
title: 'synTrack',
theme: ThemeData(
primarySwatch: primarySwatch,
useMaterial3: false,
),
routerDelegate: _appRouter.delegate(),
routeInformationParser: _appRouter.defaultRouteParser(),
Expand Down
2 changes: 1 addition & 1 deletion lib/model/common/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:syntrack/model/serializer/serializers.dart';
part 'task.g.dart';

abstract class Task implements Built<Task, TaskBuilder> {
static const NO_WORK_INTERFACE_ID = '<Work Interface ID Missing>';
static const noWorkInterfaceId = '<Work Interface ID Missing>';

String get workInterfaceId;
String get id;
Expand Down
2 changes: 0 additions & 2 deletions lib/model/work/erpnext/erpnext_activity_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ library erpnext_activity_type;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:syntrack/model/serializer/serializers.dart';

Expand Down
2 changes: 0 additions & 2 deletions lib/model/work/erpnext/erpnext_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ library erpnext_task;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:syntrack/model/serializer/serializers.dart';

Expand Down
1 change: 0 additions & 1 deletion lib/model/work/erpnext/erpnext_task_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:syntrack/model/serializer/serializers.dart';
import 'package:syntrack/model/work/erpnext/erpnext_task.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/model/work/erpnext/erpnext_timesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:syntrack/model/serializer/serializers.dart';
import 'package:syntrack/model/work/erpnext/erpnext_timesheet_log.dart';
Expand Down
2 changes: 0 additions & 2 deletions lib/model/work/erpnext/erpnext_timesheet_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ library erpnext_timesheet_data;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:syntrack/model/serializer/serializers.dart';
import 'package:syntrack/model/work/erpnext/erpnext_timesheet.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/model/work/erpnext/erpnext_timesheet_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:syntrack/model/serializer/serializers.dart';
import 'package:syntrack/model/work/erpnext/erpnext_timesheet.dart';
Expand Down
3 changes: 0 additions & 3 deletions lib/model/work/erpnext/erpnext_timesheet_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ library erpnext_timesheet_log;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:intl/intl.dart';
import 'package:syntrack/model/serializer/serializers.dart';

part 'erpnext_timesheet_log.g.dart';
Expand Down
34 changes: 18 additions & 16 deletions lib/repository/data/erpnext_data_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ final _erpNextDateTimeFormatter = DateFormat('yyyy-MM-dd HH:mm:ss');
const _apiResourcePath = 'api/resource';
const _apiMethodPath = 'api/method';

const _activityTypeResourcePath = '${_apiResourcePath}/Activity%20Type?filters=[["disabled", "=", 0]]';
const _timesheetResourcePath = '${_apiResourcePath}/Timesheet';
final _loggedInUserMethodPath = '${_apiMethodPath}/frappe.auth.get_logged_user';
const _activityTypeResourcePath = '$_apiResourcePath/Activity%20Type?filters=[["disabled", "=", 0]]';
const _timesheetResourcePath = '$_apiResourcePath/Timesheet';
const _loggedInUserMethodPath = '$_apiMethodPath/frappe.auth.get_logged_user';

const _timesheetPrefix = 'syntrack_';
const _mandatoryFirstTimeLogDescription = 'syntrack_temp_mandatory_time_log';
Expand All @@ -43,7 +43,8 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
String query,
int pageNumber,
) =>
'${_apiResourcePath}/Task' +
// ignore: prefer_adjacent_string_concatenation, prefer_interpolation_to_compose_strings
'$_apiResourcePath/Task' +
'?or_filters=[["description", "like", "%$query%"],["subject", "like", "%$query%"],["name", "like", "%$query%"]]' +
'&fields=["name","subject","project"]' +
'&limit_page_length=$_limitPageLength&limit_start=${pageNumber * _limitPageLength}';
Expand All @@ -52,15 +53,16 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
String owner,
String taskId,
) =>
'${_apiResourcePath}/Timesheet' +
// ignore: prefer_adjacent_string_concatenation, prefer_interpolation_to_compose_strings
'$_apiResourcePath/Timesheet' +
'?fields=["title", "name","docstatus","status"]' +
'&filters=[["owner","=","$owner"],["title","like","$_timesheetPrefix${taskId}_%"]]' +
'&order_by=name%20asc';

String _timesheetGetPath(
String timesheetName,
) =>
'${_apiResourcePath}/Timesheet/${timesheetName}';
'$_apiResourcePath/Timesheet/$timesheetName';

@override
Future<BookingResult> book(ErpNextConfig config, TimeEntry timeEntry) async {
Expand All @@ -78,13 +80,13 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
final timeLogName = await _createTimeLog(config, timesheet, timeEntry);

return BookingResult(
bookingId: '${timesheet.name}_${timeLogName}',
bookingId: '${timesheet.name}_$timeLogName',
duration: timeEntry.duration,
);
}

Future<String> _createTimeLog(ErpNextConfig config, ErpNextTimesheet timesheet, TimeEntry timeEntry) async {
final path = '${_timesheetResourcePath}/${timesheet.name}';
final path = '$_timesheetResourcePath/${timesheet.name}';
final tempUuidForMapping = uuid.v4();
final tempTimeLog = ErpNextTimesheetLog(
(log) => log..description = tempUuidForMapping,
Expand Down Expand Up @@ -172,12 +174,12 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
_timesheetResourcePath,
config: config,
body:
'{ "title": "${timesheetTitle}", "time_logs": [{ "description": "${_mandatoryFirstTimeLogDescription}" }] }',
'{ "title": "$timesheetTitle", "time_logs": [{ "description": "$_mandatoryFirstTimeLogDescription" }] }',
fromJson: ErpNextTimesheetData.fromJson,
).then((value) => value.data);
}

String _getTimesheetTitle(Task task, int suffix) => '${_timesheetPrefix}${task.id}_${suffix}';
String _getTimesheetTitle(Task task, int suffix) => '$_timesheetPrefix${task.id}_$suffix';

@override
Future<void> deleteBooking(ErpNextConfig config, TimeEntry timeEntry) async {
Expand All @@ -186,7 +188,7 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {

final parsedBookingId = _parseTimesheetLogBookingId(timeEntry.bookingId!);
final timesheet = await _getTimesheet(config, parsedBookingId.timesheetName);
final path = '${_timesheetResourcePath}/${timesheet.name}';
final path = '$_timesheetResourcePath/${timesheet.name}';

if (timesheet.docstatus == 1) {
// submitted
Expand All @@ -202,7 +204,7 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
throw DeleteBookingFailedException('Could not find Timesheet Log ${parsedBookingId.timesheetLogName}');
}

if (newTimesheet.timeLogs.length <= 0) {
if (newTimesheet.timeLogs.isEmpty) {
final response = await _deleteOrFail(path, config: config);
final responseJson = jsonDecode(response.body);
if (responseJson['message'] == null || responseJson['message'] != 'ok') {
Expand Down Expand Up @@ -310,7 +312,7 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
if (!_isResponse2XX(response)) {
final message = [
'GET - ',
'[${response.statusCode} ${response.reasonPhrase != null ? response.reasonPhrase : ''}]',
'[${response.statusCode} ${response.reasonPhrase ?? ''}]',
if (response.body.trim().isNotEmpty) response.body,
].join(" ");
throw Exception('request failed: $message');
Expand Down Expand Up @@ -343,7 +345,7 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
if (!_isResponse2XX(response)) {
final message = [
'POST - ',
'[${response.statusCode} ${response.reasonPhrase != null ? response.reasonPhrase : ''}]',
'[${response.statusCode} ${response.reasonPhrase ?? ''}]',
if (response.body.trim().isNotEmpty) response.body,
].join(" ");
throw Exception('request failed: $message');
Expand Down Expand Up @@ -376,7 +378,7 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
if (!_isResponse2XX(response)) {
final message = [
'PUT - ',
'[${response.statusCode} ${response.reasonPhrase != null ? response.reasonPhrase : ''}]',
'[${response.statusCode} ${response.reasonPhrase ?? ''}]',
if (response.body.trim().isNotEmpty) response.body,
].join(" ");
throw Exception('request failed: $message');
Expand All @@ -399,7 +401,7 @@ class ErpNextDataProvider extends WorkDataProvider<ErpNextConfig> {
if (!_isResponse2XX(response)) {
final message = [
'DELETE - ',
'[${response.statusCode} ${response.reasonPhrase != null ? response.reasonPhrase : ''}]',
'[${response.statusCode} ${response.reasonPhrase ?? ''}]',
if (response.body.trim().isNotEmpty) response.body,
].join(" ");
throw Exception('request failed: $message');
Expand Down
Loading

0 comments on commit 6c74d77

Please sign in to comment.