From 4accbd53f365b608eba59b06115ca8e4cd89ea2d Mon Sep 17 00:00:00 2001 From: Bhasher Date: Wed, 14 Jun 2023 23:24:04 +0200 Subject: [PATCH] Massive dir refactoring --- .../external_connector.dart | 0 .../connectors => data}/local/generic.dart | 0 .../connectors => data}/local/instance.dart | 4 +- .../connectors => data}/local/item.dart | 8 +- .../connectors => data}/local/item_part.dart | 6 +- .../local/participant.dart | 6 +- .../connectors => data}/local/project.dart | 10 +- .../connectors => data}/local/provider.dart | 4 +- .../connectors => data}/pocketbase/item.dart | 12 +- .../pocketbase/item_part.dart | 13 +- .../pocketbase/participant.dart | 10 +- .../pocketbase/project.dart | 6 +- .../pocketbase/provider.dart | 8 +- lib/{model/connectors => data}/provider.dart | 4 +- lib/main.dart | 65 ++++++++- lib/{model => models}/app_data.dart | 10 +- lib/{model => models}/bill_data.dart | 2 +- lib/{model => models}/data.dart | 2 +- lib/{model => models}/instance.dart | 2 +- lib/{model => models}/item.dart | 6 +- lib/{model => models}/item_part.dart | 2 +- lib/{model => models}/participant.dart | 4 +- lib/{model => models}/project.dart | 10 +- lib/{model => models}/project_data.dart | 0 .../instances/instance_tile.dart | 10 +- .../instances/instances_list_page.dart | 6 +- lib/screens/main_screen.dart | 53 ------- .../new_instance/new_instance_page.dart | 8 +- .../new_instance/new_instance_pocketbase.dart | 0 .../new_instance/new_instance_selector.dart | 2 +- .../new_project/new_project_page.dart | 18 +-- .../new_project/participant_tile.dart | 6 +- lib/screens/new_project_screen.dart | 133 ------------------ .../project/balances/balancing_page_part.dart | 4 +- .../project/balances/refund_page_part.dart | 6 +- .../project/expenses/entry_table.dart | 0 .../project/expenses/item_list.dart | 19 ++- .../project/expenses/new_entry.dart | 20 +-- lib/screens/project/new_project.dart | 122 ++++++++++++++++ .../project/project_page.dart | 6 +- .../projects_list/projects_list.dart | 13 +- .../projects_list/projects_list_page.dart | 2 +- lib/screens/setup_screen.dart | 22 --- lib/screens/splash_screen.dart | 29 ---- .../database.dart} | 20 +-- lib/utils/{extenders => ext}/datetime.dart | 1 + .../collections.dart => ext/list.dart} | 8 +- lib/utils/ext/record_model.dart | 7 + .../record_service.dart} | 6 - lib/utils/ext/set.dart | 7 + lib/utils/{extenders => ext}/string.dart | 0 .../text_input_formatter.dart} | 0 lib/utils/ext/time.dart | 98 +++++++++++++ .../{dialogs => helper}/confirm_box.dart | 0 .../{navigator => helper}/navigator.dart | 0 lib/utils/helper/random.dart | 14 ++ lib/utils/{colors.dart => helper/theme.dart} | 27 ++++ lib/utils/time.dart | 97 ------------- lib/{utils/tiles => widgets}/header_tile.dart | 0 lib/{screens => widgets}/new_screen.dart | 0 .../switches => widgets}/text_switch.dart | 0 61 files changed, 472 insertions(+), 486 deletions(-) rename lib/{model/connectors => data}/external_connector.dart (100%) rename lib/{model/connectors => data}/local/generic.dart (100%) rename lib/{model/connectors => data}/local/instance.dart (88%) rename lib/{model/connectors => data}/local/item.dart (84%) rename lib/{model/connectors => data}/local/item_part.dart (78%) rename lib/{model/connectors => data}/local/participant.dart (79%) rename lib/{model/connectors => data}/local/project.dart (90%) rename lib/{model/connectors => data}/local/provider.dart (89%) rename lib/{model/connectors => data}/pocketbase/item.dart (91%) rename lib/{model/connectors => data}/pocketbase/item_part.dart (90%) rename lib/{model/connectors => data}/pocketbase/participant.dart (91%) rename lib/{model/connectors => data}/pocketbase/project.dart (93%) rename lib/{model/connectors => data}/pocketbase/provider.dart (94%) rename lib/{model/connectors => data}/provider.dart (94%) rename lib/{model => models}/app_data.dart (92%) rename lib/{model => models}/bill_data.dart (98%) rename lib/{model => models}/data.dart (88%) rename lib/{model => models}/instance.dart (97%) rename lib/{model => models}/item.dart (97%) rename lib/{model => models}/item_part.dart (98%) rename lib/{model => models}/participant.dart (95%) rename lib/{model => models}/project.dart (96%) rename lib/{model => models}/project_data.dart (100%) rename lib/{components/pages => screens}/instances/instance_tile.dart (89%) rename lib/{components/pages => screens}/instances/instances_list_page.dart (92%) delete mode 100644 lib/screens/main_screen.dart rename lib/{components/pages => screens}/new_instance/new_instance_page.dart (95%) rename lib/{components/pages => screens}/new_instance/new_instance_pocketbase.dart (100%) rename lib/{components/pages => screens}/new_instance/new_instance_selector.dart (97%) rename lib/{components/pages => screens}/new_project/new_project_page.dart (93%) rename lib/{components/pages => screens}/new_project/participant_tile.dart (96%) delete mode 100644 lib/screens/new_project_screen.dart rename lib/{components/pages => screens}/project/balances/balancing_page_part.dart (97%) rename lib/{components/pages => screens}/project/balances/refund_page_part.dart (95%) rename lib/{components/pages => screens}/project/expenses/entry_table.dart (100%) rename lib/{components/pages => screens}/project/expenses/item_list.dart (95%) rename lib/{components/pages => screens}/project/expenses/new_entry.dart (96%) create mode 100644 lib/screens/project/new_project.dart rename lib/{components/pages => screens}/project/project_page.dart (97%) rename lib/{components/pages => screens}/projects_list/projects_list.dart (91%) rename lib/{components/pages => screens}/projects_list/projects_list_page.dart (96%) delete mode 100644 lib/screens/setup_screen.dart delete mode 100644 lib/screens/splash_screen.dart rename lib/{db/splitr_database.dart => services/database.dart} (89%) rename lib/utils/{extenders => ext}/datetime.dart (99%) rename lib/utils/{extenders/collections.dart => ext/list.dart} (67%) create mode 100644 lib/utils/ext/record_model.dart rename lib/utils/{extenders/pocketbase.dart => ext/record_service.dart} (62%) create mode 100644 lib/utils/ext/set.dart rename lib/utils/{extenders => ext}/string.dart (100%) rename lib/utils/{formatter/decimal.dart => ext/text_input_formatter.dart} (100%) create mode 100644 lib/utils/ext/time.dart rename lib/utils/{dialogs => helper}/confirm_box.dart (100%) rename lib/utils/{navigator => helper}/navigator.dart (100%) create mode 100644 lib/utils/helper/random.dart rename lib/utils/{colors.dart => helper/theme.dart} (57%) delete mode 100644 lib/utils/time.dart rename lib/{utils/tiles => widgets}/header_tile.dart (100%) rename lib/{screens => widgets}/new_screen.dart (100%) rename lib/{utils/switches => widgets}/text_switch.dart (100%) diff --git a/lib/model/connectors/external_connector.dart b/lib/data/external_connector.dart similarity index 100% rename from lib/model/connectors/external_connector.dart rename to lib/data/external_connector.dart diff --git a/lib/model/connectors/local/generic.dart b/lib/data/local/generic.dart similarity index 100% rename from lib/model/connectors/local/generic.dart rename to lib/data/local/generic.dart diff --git a/lib/model/connectors/local/instance.dart b/lib/data/local/instance.dart similarity index 88% rename from lib/model/connectors/local/instance.dart rename to lib/data/local/instance.dart index a5a75c8..cdfd138 100644 --- a/lib/model/connectors/local/instance.dart +++ b/lib/data/local/instance.dart @@ -1,7 +1,7 @@ import 'package:sqflite/sqflite.dart'; -import '../../app_data.dart'; -import '../../instance.dart'; +import '../../models/app_data.dart'; +import '../../models/instance.dart'; const String tableInstances = 'instances'; diff --git a/lib/model/connectors/local/item.dart b/lib/data/local/item.dart similarity index 84% rename from lib/model/connectors/local/item.dart rename to lib/data/local/item.dart index b5c306e..e334c51 100644 --- a/lib/model/connectors/local/item.dart +++ b/lib/data/local/item.dart @@ -1,9 +1,9 @@ -import 'package:splitr/model/connectors/local/generic.dart'; +import 'package:splitr/data/local/generic.dart'; import 'package:sqflite/sqlite_api.dart'; -import '../../app_data.dart'; -import '../../item.dart'; -import '../../item_part.dart'; +import '../../models/app_data.dart'; +import '../../models/item.dart'; +import '../../models/item_part.dart'; import 'item_part.dart'; const String tableItems = 'items'; diff --git a/lib/model/connectors/local/item_part.dart b/lib/data/local/item_part.dart similarity index 78% rename from lib/model/connectors/local/item_part.dart rename to lib/data/local/item_part.dart index ed41e15..1e8b9f9 100644 --- a/lib/model/connectors/local/item_part.dart +++ b/lib/data/local/item_part.dart @@ -1,8 +1,8 @@ -import 'package:splitr/model/connectors/local/generic.dart'; +import 'package:splitr/data/local/generic.dart'; import 'package:sqflite/sqflite.dart'; -import '../../app_data.dart'; -import '../../item_part.dart'; +import '../../models/app_data.dart'; +import '../../models/item_part.dart'; const String tableItemParts = 'itemParts'; diff --git a/lib/model/connectors/local/participant.dart b/lib/data/local/participant.dart similarity index 79% rename from lib/model/connectors/local/participant.dart rename to lib/data/local/participant.dart index 44e8b59..2d89c7b 100644 --- a/lib/model/connectors/local/participant.dart +++ b/lib/data/local/participant.dart @@ -1,8 +1,8 @@ -import 'package:splitr/model/connectors/local/generic.dart'; +import 'package:splitr/data/local/generic.dart'; import 'package:sqflite/sqflite.dart'; -import '../../app_data.dart'; -import '../../participant.dart'; +import '../../models/app_data.dart'; +import '../../models/participant.dart'; const String tableParticipants = 'participants'; diff --git a/lib/model/connectors/local/project.dart b/lib/data/local/project.dart similarity index 90% rename from lib/model/connectors/local/project.dart rename to lib/data/local/project.dart index 970217a..3bcf671 100644 --- a/lib/model/connectors/local/project.dart +++ b/lib/data/local/project.dart @@ -1,10 +1,10 @@ -import 'package:splitr/model/connectors/local/generic.dart'; +import 'package:splitr/data/local/generic.dart'; import 'package:sqflite/sqflite.dart'; -import '../../app_data.dart'; -import '../../item.dart'; -import '../../participant.dart'; -import '../../project.dart'; +import '../../models/app_data.dart'; +import '../../models/item.dart'; +import '../../models/participant.dart'; +import '../../models/project.dart'; import 'item.dart'; import 'participant.dart'; diff --git a/lib/model/connectors/local/provider.dart b/lib/data/local/provider.dart similarity index 89% rename from lib/model/connectors/local/provider.dart rename to lib/data/local/provider.dart index dc225f3..878a06b 100644 --- a/lib/model/connectors/local/provider.dart +++ b/lib/data/local/provider.dart @@ -1,5 +1,5 @@ -import '../../instance.dart'; -import '../../project.dart'; +import '../../models/instance.dart'; +import '../../models/project.dart'; import '../provider.dart'; class LocalProvider extends Provider { diff --git a/lib/model/connectors/pocketbase/item.dart b/lib/data/pocketbase/item.dart similarity index 91% rename from lib/model/connectors/pocketbase/item.dart rename to lib/data/pocketbase/item.dart index dd93ca2..5075389 100644 --- a/lib/model/connectors/pocketbase/item.dart +++ b/lib/data/pocketbase/item.dart @@ -1,12 +1,12 @@ import 'package:pocketbase/pocketbase.dart'; -import 'package:splitr/model/participant.dart'; -import 'package:splitr/utils/extenders/datetime.dart'; -import 'package:splitr/utils/extenders/collections.dart'; -import 'package:splitr/utils/extenders/pocketbase.dart'; +import 'package:splitr/models/participant.dart'; +import 'package:splitr/utils/ext/datetime.dart'; +import 'package:splitr/utils/ext/list.dart'; +import 'package:splitr/utils/ext/record_service.dart'; import 'package:tuple/tuple.dart'; -import '../../item.dart'; -import '../../project.dart'; +import '../../models/item.dart'; +import '../../models/project.dart'; import 'item_part.dart'; class PocketBaseItemsFields { diff --git a/lib/model/connectors/pocketbase/item_part.dart b/lib/data/pocketbase/item_part.dart similarity index 90% rename from lib/model/connectors/pocketbase/item_part.dart rename to lib/data/pocketbase/item_part.dart index 0f6dce5..58e4f64 100644 --- a/lib/model/connectors/pocketbase/item_part.dart +++ b/lib/data/pocketbase/item_part.dart @@ -1,13 +1,12 @@ import 'package:pocketbase/pocketbase.dart'; -import 'package:splitr/utils/extenders/datetime.dart'; -import 'package:splitr/utils/extenders/collections.dart'; -import 'package:splitr/utils/extenders/pocketbase.dart'; +import 'package:splitr/utils/ext/datetime.dart'; +import 'package:splitr/utils/ext/record_model.dart'; +import 'package:splitr/utils/ext/record_service.dart'; import 'package:tuple/tuple.dart'; -import '../../item.dart'; -import '../../item_part.dart'; -import '../../participant.dart'; -import '../../project.dart'; +import '../../models/item.dart'; +import '../../models/item_part.dart'; +import '../../models/participant.dart'; class PocketBaseItemPartsFields { static const String id = "id"; diff --git a/lib/model/connectors/pocketbase/participant.dart b/lib/data/pocketbase/participant.dart similarity index 91% rename from lib/model/connectors/pocketbase/participant.dart rename to lib/data/pocketbase/participant.dart index c014418..a249a47 100644 --- a/lib/model/connectors/pocketbase/participant.dart +++ b/lib/data/pocketbase/participant.dart @@ -1,11 +1,11 @@ import 'package:pocketbase/pocketbase.dart'; -import 'package:splitr/utils/extenders/datetime.dart'; -import 'package:splitr/utils/extenders/collections.dart'; -import 'package:splitr/utils/extenders/pocketbase.dart'; +import 'package:splitr/utils/ext/datetime.dart'; +import 'package:splitr/utils/ext/list.dart'; +import 'package:splitr/utils/ext/record_service.dart'; import 'package:tuple/tuple.dart'; -import '../../participant.dart'; -import '../../project.dart'; +import '../../models/participant.dart'; +import '../../models/project.dart'; class PocketBaseParticipantFields { static const String id = "id"; diff --git a/lib/model/connectors/pocketbase/project.dart b/lib/data/pocketbase/project.dart similarity index 93% rename from lib/model/connectors/pocketbase/project.dart rename to lib/data/pocketbase/project.dart index 8bf72b7..f6bd1ed 100644 --- a/lib/model/connectors/pocketbase/project.dart +++ b/lib/data/pocketbase/project.dart @@ -1,8 +1,8 @@ import 'package:pocketbase/pocketbase.dart'; -import 'package:splitr/utils/extenders/datetime.dart'; -import 'package:splitr/utils/extenders/pocketbase.dart'; +import 'package:splitr/utils/ext/datetime.dart'; +import 'package:splitr/utils/ext/record_service.dart'; -import '../../project.dart'; +import '../../models/project.dart'; class PocketBaseProjectFields { static const String name = "name"; diff --git a/lib/model/connectors/pocketbase/provider.dart b/lib/data/pocketbase/provider.dart similarity index 94% rename from lib/model/connectors/pocketbase/provider.dart rename to lib/data/pocketbase/provider.dart index ab6913f..733e46e 100644 --- a/lib/model/connectors/pocketbase/provider.dart +++ b/lib/data/pocketbase/provider.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:pocketbase/pocketbase.dart'; -import '../../instance.dart'; -import '../../item.dart'; -import '../../item_part.dart'; -import '../../project.dart'; +import '../../models/instance.dart'; +import '../../models/item.dart'; +import '../../models/item_part.dart'; +import '../../models/project.dart'; import '../provider.dart'; import 'item.dart'; import 'item_part.dart'; diff --git a/lib/model/connectors/provider.dart b/lib/data/provider.dart similarity index 94% rename from lib/model/connectors/provider.dart rename to lib/data/provider.dart index efa78f1..dae5b9b 100644 --- a/lib/model/connectors/provider.dart +++ b/lib/data/provider.dart @@ -1,5 +1,5 @@ -import '../instance.dart'; -import '../project.dart'; +import '../models/instance.dart'; +import '../models/project.dart'; import 'local/provider.dart'; import 'pocketbase/provider.dart'; diff --git a/lib/main.dart b/lib/main.dart index 7bea1c5..327b0e0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,10 @@ +import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; -import 'model/app_data.dart'; -import 'screens/main_screen.dart'; -import 'screens/setup_screen.dart'; -import 'screens/splash_screen.dart'; +import 'screens/project/project_page.dart'; +import 'screens/projects_list/projects_list_page.dart'; +import 'models/app_data.dart'; +import 'screens/project/new_project.dart'; +import 'utils/helper/theme.dart'; void main() async { runApp(const SplashScreen()); @@ -13,3 +15,58 @@ void main() async { runApp(const MainScreen()); } } + +class SplashScreen extends StatelessWidget { + const SplashScreen({super.key}); + + @override + Widget build(BuildContext context) { + return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) { + return MaterialApp( + theme: defaultTheme, + darkTheme: defaultDarkTheme, + home: const Scaffold( + body: Center( + child: Text("Starting up Splitr ..."), + ), + ), + ); + }); + } +} + +class MainScreen extends StatelessWidget { + const MainScreen({super.key}); + + @override + Widget build(BuildContext context) { + return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) { + return MaterialApp( + title: 'Splitr', + theme: defaultTheme, + darkTheme: defaultDarkTheme, + themeMode: ThemeMode.system, + home: AppData.current == null + ? const ProjectsListPage() + : ProjectPage(AppData.current!), + ); + }); + } +} + +class SetupScreen extends StatelessWidget { + const SetupScreen({super.key}); + + @override + Widget build(BuildContext context) { + return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) { + return MaterialApp( + title: 'Splitr', + theme: defaultTheme, + darkTheme: defaultDarkTheme, + themeMode: ThemeMode.system, + home: NewProjectScreen(first: true), + ); + }); + } +} diff --git a/lib/model/app_data.dart b/lib/models/app_data.dart similarity index 92% rename from lib/model/app_data.dart rename to lib/models/app_data.dart index bb94070..78737ea 100644 --- a/lib/model/app_data.dart +++ b/lib/models/app_data.dart @@ -2,13 +2,13 @@ import 'package:app_links/app_links.dart'; import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:splitr/model/connectors/local/project.dart'; -import 'package:splitr/utils/extenders/collections.dart'; +import 'package:splitr/data/local/project.dart'; +import 'package:splitr/utils/ext/set.dart'; import 'package:sqflite/sqflite.dart'; -import '../db/splitr_database.dart'; -import '../screens/main_screen.dart'; -import '../screens/new_project_screen.dart'; +import '../screens/project/new_project.dart'; +import '../services/database.dart'; +import '../utils/helper/theme.dart'; import 'instance.dart'; import 'project.dart'; diff --git a/lib/model/bill_data.dart b/lib/models/bill_data.dart similarity index 98% rename from lib/model/bill_data.dart rename to lib/models/bill_data.dart index 05e0771..34b5a93 100644 --- a/lib/model/bill_data.dart +++ b/lib/models/bill_data.dart @@ -1,4 +1,4 @@ -import 'package:splitr/utils/extenders/collections.dart'; +import 'package:splitr/utils/ext/list.dart'; import 'item_part.dart'; import 'participant.dart'; diff --git a/lib/model/data.dart b/lib/models/data.dart similarity index 88% rename from lib/model/data.dart rename to lib/models/data.dart index c1c048b..a63bca0 100644 --- a/lib/model/data.dart +++ b/lib/models/data.dart @@ -1,4 +1,4 @@ -import 'package:splitr/model/connectors/local/generic.dart'; +import 'package:splitr/data/local/generic.dart'; abstract class Data { Data({ diff --git a/lib/model/instance.dart b/lib/models/instance.dart similarity index 97% rename from lib/model/instance.dart rename to lib/models/instance.dart index d6312ef..21ba0aa 100644 --- a/lib/model/instance.dart +++ b/lib/models/instance.dart @@ -1,7 +1,7 @@ import 'dart:convert'; import 'app_data.dart'; -import 'connectors/local/instance.dart'; +import '../data/local/instance.dart'; class InstanceFields { static const values = [ diff --git a/lib/model/item.dart b/lib/models/item.dart similarity index 97% rename from lib/model/item.dart rename to lib/models/item.dart index 8147442..5bc501c 100644 --- a/lib/model/item.dart +++ b/lib/models/item.dart @@ -1,11 +1,11 @@ -import 'package:splitr/model/data.dart'; -import 'package:splitr/utils/extenders/collections.dart'; +import 'package:splitr/models/data.dart'; +import 'package:splitr/utils/ext/list.dart'; import 'item_part.dart'; import 'participant.dart'; import 'project.dart'; -import 'connectors/local/item.dart'; +import '../data/local/item.dart'; class ItemFields { static const values = [ diff --git a/lib/model/item_part.dart b/lib/models/item_part.dart similarity index 98% rename from lib/model/item_part.dart rename to lib/models/item_part.dart index 4691349..f83e29f 100644 --- a/lib/model/item_part.dart +++ b/lib/models/item_part.dart @@ -2,7 +2,7 @@ import 'data.dart'; import 'participant.dart'; import 'item.dart'; -import 'connectors/local/item_part.dart'; +import '../data/local/item_part.dart'; class ItemPartFields { static const values = [ diff --git a/lib/model/participant.dart b/lib/models/participant.dart similarity index 95% rename from lib/model/participant.dart rename to lib/models/participant.dart index 36523ca..5ac666e 100644 --- a/lib/model/participant.dart +++ b/lib/models/participant.dart @@ -1,6 +1,6 @@ -import 'package:splitr/model/data.dart'; +import 'package:splitr/models/data.dart'; -import 'connectors/local/participant.dart'; +import '../data/local/participant.dart'; import 'project.dart'; class ParticipantFields { diff --git a/lib/model/project.dart b/lib/models/project.dart similarity index 96% rename from lib/model/project.dart rename to lib/models/project.dart index 84d4930..1d32add 100644 --- a/lib/model/project.dart +++ b/lib/models/project.dart @@ -1,11 +1,11 @@ -import 'package:splitr/model/data.dart'; -import 'package:splitr/utils/extenders/collections.dart'; +import 'package:splitr/models/data.dart'; +import 'package:splitr/utils/ext/set.dart'; import 'package:tuple/tuple.dart'; -import '../screens/new_project_screen.dart'; +import '../utils/helper/random.dart'; import 'app_data.dart'; -import 'connectors/local/project.dart'; -import 'connectors/provider.dart'; +import '../data/local/project.dart'; +import '../data/provider.dart'; import 'instance.dart'; import 'item.dart'; import 'item_part.dart'; diff --git a/lib/model/project_data.dart b/lib/models/project_data.dart similarity index 100% rename from lib/model/project_data.dart rename to lib/models/project_data.dart diff --git a/lib/components/pages/instances/instance_tile.dart b/lib/screens/instances/instance_tile.dart similarity index 89% rename from lib/components/pages/instances/instance_tile.dart rename to lib/screens/instances/instance_tile.dart index 29c2c3c..b4cc80c 100644 --- a/lib/components/pages/instances/instance_tile.dart +++ b/lib/screens/instances/instance_tile.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:splitr/model/connectors/local/instance.dart'; +import 'package:splitr/data/local/instance.dart'; -import '../../../model/app_data.dart'; -import '../../../model/instance.dart'; -import '../../../utils/dialogs/confirm_box.dart'; -import '../../../utils/navigator/navigator.dart'; +import '../../models/app_data.dart'; +import '../../models/instance.dart'; +import '../../utils/helper/confirm_box.dart'; +import '../../utils/helper/navigator.dart'; import '../new_instance/new_instance_page.dart'; class InstanceTile extends StatefulWidget { diff --git a/lib/components/pages/instances/instances_list_page.dart b/lib/screens/instances/instances_list_page.dart similarity index 92% rename from lib/components/pages/instances/instances_list_page.dart rename to lib/screens/instances/instances_list_page.dart index 0d49776..1893e6b 100644 --- a/lib/components/pages/instances/instances_list_page.dart +++ b/lib/screens/instances/instances_list_page.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import '../../../model/app_data.dart'; -import '../../../model/instance.dart'; -import '../../../utils/navigator/navigator.dart'; +import '../../models/app_data.dart'; +import '../../models/instance.dart'; +import '../../utils/helper/navigator.dart'; import '../new_instance/new_instance_page.dart'; import 'instance_tile.dart'; diff --git a/lib/screens/main_screen.dart b/lib/screens/main_screen.dart deleted file mode 100644 index 8bf92b0..0000000 --- a/lib/screens/main_screen.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:dynamic_color/dynamic_color.dart'; -import 'package:flutter/material.dart'; - -import '../components/pages/project/project_page.dart'; -import '../components/pages/projects_list/projects_list_page.dart'; -import '../model/app_data.dart'; -import '../utils/colors.dart'; - -final defaultLightColorScheme = ColorScheme.fromSwatch( - primarySwatch: Colors.red, -); - -final defaultDarkColorScheme = ColorScheme.fromSwatch( - primarySwatch: ColorModel.red, - primaryColorDark: Colors.red, - brightness: Brightness.dark, - backgroundColor: Colors.black87, -); - -final defaultTheme = ThemeData( - colorScheme: defaultLightColorScheme, - brightness: Brightness.light, - useMaterial3: true, - appBarTheme: AppBarTheme(backgroundColor: defaultDarkColorScheme.primary), - inputDecorationTheme: const InputDecorationTheme( - border: OutlineInputBorder(), - )); - -final defaultDarkTheme = ThemeData( - useMaterial3: true, - brightness: Brightness.dark, - colorScheme: defaultDarkColorScheme, - appBarTheme: AppBarTheme(backgroundColor: defaultDarkColorScheme.primary), -); - -class MainScreen extends StatelessWidget { - const MainScreen({super.key}); - - @override - Widget build(BuildContext context) { - return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) { - return MaterialApp( - title: 'Splitr', - theme: defaultTheme, - darkTheme: defaultDarkTheme, - themeMode: ThemeMode.system, - home: AppData.current == null - ? const ProjectsListPage() - : ProjectPage(AppData.current!), - ); - }); - } -} diff --git a/lib/components/pages/new_instance/new_instance_page.dart b/lib/screens/new_instance/new_instance_page.dart similarity index 95% rename from lib/components/pages/new_instance/new_instance_page.dart rename to lib/screens/new_instance/new_instance_page.dart index bd9379d..2bafa8c 100644 --- a/lib/components/pages/new_instance/new_instance_page.dart +++ b/lib/screens/new_instance/new_instance_page.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:pocketbase/pocketbase.dart'; -import '../../../model/app_data.dart'; -import '../../../model/connectors/pocketbase/provider.dart'; -import '../../../model/connectors/provider.dart'; -import '../../../model/instance.dart'; +import '../../models/app_data.dart'; +import '../../data/pocketbase/provider.dart'; +import '../../data/provider.dart'; +import '../../models/instance.dart'; import 'new_instance_selector.dart'; class NewInstancePage extends StatelessWidget { diff --git a/lib/components/pages/new_instance/new_instance_pocketbase.dart b/lib/screens/new_instance/new_instance_pocketbase.dart similarity index 100% rename from lib/components/pages/new_instance/new_instance_pocketbase.dart rename to lib/screens/new_instance/new_instance_pocketbase.dart diff --git a/lib/components/pages/new_instance/new_instance_selector.dart b/lib/screens/new_instance/new_instance_selector.dart similarity index 97% rename from lib/components/pages/new_instance/new_instance_selector.dart rename to lib/screens/new_instance/new_instance_selector.dart index 61c7fdd..20ff39f 100644 --- a/lib/components/pages/new_instance/new_instance_selector.dart +++ b/lib/screens/new_instance/new_instance_selector.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../../../utils/tiles/header_tile.dart'; +import '../../widgets/header_tile.dart'; import 'new_instance_page.dart'; import 'new_instance_pocketbase.dart'; diff --git a/lib/components/pages/new_project/new_project_page.dart b/lib/screens/new_project/new_project_page.dart similarity index 93% rename from lib/components/pages/new_project/new_project_page.dart rename to lib/screens/new_project/new_project_page.dart index 29a61ed..e4a3af9 100644 --- a/lib/components/pages/new_project/new_project_page.dart +++ b/lib/screens/new_project/new_project_page.dart @@ -1,15 +1,15 @@ import 'package:flutter/material.dart'; import 'package:select_form_field/select_form_field.dart'; -import 'package:splitr/utils/extenders/collections.dart'; -import 'package:splitr/utils/extenders/string.dart'; +import 'package:splitr/utils/ext/list.dart'; +import 'package:splitr/utils/ext/string.dart'; -import '../../../model/app_data.dart'; -import '../../../model/instance.dart'; -import '../../../model/project.dart'; -import '../../../model/project_data.dart'; -import '../../../utils/navigator/navigator.dart'; -import '../../../utils/switches/text_switch.dart'; -import '../../../utils/tiles/header_tile.dart'; +import '../../widgets/header_tile.dart'; +import '../../widgets/text_switch.dart'; +import '../../models/app_data.dart'; +import '../../models/instance.dart'; +import '../../models/project.dart'; +import '../../models/project_data.dart'; +import '../../utils/helper/navigator.dart'; import 'participant_tile.dart'; import '../instances/instances_list_page.dart'; diff --git a/lib/components/pages/new_project/participant_tile.dart b/lib/screens/new_project/participant_tile.dart similarity index 96% rename from lib/components/pages/new_project/participant_tile.dart rename to lib/screens/new_project/participant_tile.dart index b3067bf..d180b4b 100644 --- a/lib/components/pages/new_project/participant_tile.dart +++ b/lib/screens/new_project/participant_tile.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import '../../../model/participant.dart'; -import '../../../model/project.dart'; -import '../../../utils/dialogs/confirm_box.dart'; +import '../../models/participant.dart'; +import '../../models/project.dart'; +import '../../utils/helper/confirm_box.dart'; class ParticipantTile extends StatefulWidget { ParticipantTile({ diff --git a/lib/screens/new_project_screen.dart b/lib/screens/new_project_screen.dart deleted file mode 100644 index e09999c..0000000 --- a/lib/screens/new_project_screen.dart +++ /dev/null @@ -1,133 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:pocketbase/pocketbase.dart'; - -import '../components/pages/new_project/new_project_page.dart'; -import '../model/app_data.dart'; -import '../model/connectors/pocketbase/provider.dart'; -import '../model/connectors/provider.dart'; -import '../model/instance.dart'; -import '../model/project.dart'; -import '../model/project_data.dart'; -import 'main_screen.dart'; -import 'new_screen.dart'; - -class NewProjectScreen extends StatelessWidget { - NewProjectScreen({ - this.first = false, - this.project, - this.code, - this.instance, - super.key, - }); - - final bool first; - Project? project; - final String? code; - final Instance? instance; - - ProjectData setupData = ProjectData(); - - @override - Widget build(BuildContext context) { - setupData.instance = instance; - bool newProject = project == null; - - if (newProject && code != null) { - setupData.projectName = code; - setupData.join = true; - } - - return NewScreen( - title: first - ? 'Create your first project!' - : newProject - ? 'New project' - : 'Update project', - buttonTitle: first - ? 'Let\'s started' - : newProject - ? 'Create' - : 'Update', - child: NewProjectPage( - projectData: setupData, - project: project, - ), - onValidate: (context, formKey) async { - if (formKey.currentState != null && formKey.currentState!.validate()) { - if (newProject) { - project = Project( - name: setupData.projectName!, - code: setupData.join ? null : getRandom(5), - instance: setupData.instance!, - ); - } else { - project!.name = setupData.projectName!; - project!.provider = Provider.initFromInstance( - project!, - setupData.instance!, - ); - } - try { - // await project!.provider.connect(); - AppData.current = project; - await project!.conn.save(); - if (setupData.join) { - await project!.provider.joinWithTitle(); - await project!.sync(); - } - } on ClientException catch (e) { - PocketBaseProvider.onClientException(e, context); - return; - } catch (e) { - if (context.mounted) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(e.toString()), - ), - ); - } - return; - } - if (first) { - AppData.firstRun = false; - runApp(const MainScreen()); - } else { - if (context.mounted) { - if (newProject) { - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => NewProjectScreen( - project: project, - ), - ), - ); - } else { - if (Navigator.canPop(context)) { - Navigator.pop(context, true); - } else { - runApp(const MainScreen()); - } - } - } - } - } - }, - ); - } -} - -String getRandom(int length) { - const ch = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'; - Random r = Random(); - return String.fromCharCodes( - Iterable.generate( - length, - (_) => ch.codeUnitAt( - r.nextInt(ch.length), - ), - ), - ); -} diff --git a/lib/components/pages/project/balances/balancing_page_part.dart b/lib/screens/project/balances/balancing_page_part.dart similarity index 97% rename from lib/components/pages/project/balances/balancing_page_part.dart rename to lib/screens/project/balances/balancing_page_part.dart index b03a623..53a9152 100644 --- a/lib/components/pages/project/balances/balancing_page_part.dart +++ b/lib/screens/project/balances/balancing_page_part.dart @@ -2,8 +2,8 @@ import 'dart:math'; import 'package:flutter/material.dart'; -import '../../../../model/participant.dart'; -import '../../../../model/project.dart'; +import '../../../models/participant.dart'; +import '../../../models/project.dart'; import 'refund_page_part.dart'; class BalancingPagePart extends StatefulWidget { diff --git a/lib/components/pages/project/balances/refund_page_part.dart b/lib/screens/project/balances/refund_page_part.dart similarity index 95% rename from lib/components/pages/project/balances/refund_page_part.dart rename to lib/screens/project/balances/refund_page_part.dart index ebe57c5..1b70397 100644 --- a/lib/components/pages/project/balances/refund_page_part.dart +++ b/lib/screens/project/balances/refund_page_part.dart @@ -2,9 +2,9 @@ import 'dart:math'; import 'package:flutter/material.dart'; -import '../../../../model/participant.dart'; -import '../../../../model/project.dart'; -import '../../../../utils/tiles/header_tile.dart'; +import '../../../models/participant.dart'; +import '../../../models/project.dart'; +import '../../../widgets/header_tile.dart'; List getRefundPageTiles({ required final Project project, diff --git a/lib/components/pages/project/expenses/entry_table.dart b/lib/screens/project/expenses/entry_table.dart similarity index 100% rename from lib/components/pages/project/expenses/entry_table.dart rename to lib/screens/project/expenses/entry_table.dart diff --git a/lib/components/pages/project/expenses/item_list.dart b/lib/screens/project/expenses/item_list.dart similarity index 95% rename from lib/components/pages/project/expenses/item_list.dart rename to lib/screens/project/expenses/item_list.dart index 2357423..a440015 100644 --- a/lib/components/pages/project/expenses/item_list.dart +++ b/lib/screens/project/expenses/item_list.dart @@ -2,15 +2,15 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; -import 'package:splitr/model/item_part.dart'; -import 'package:splitr/utils/extenders/collections.dart'; +import 'package:splitr/models/item_part.dart'; +import 'package:splitr/utils/ext/list.dart'; import 'package:tuple/tuple.dart'; -import '../../../../utils/extenders/string.dart'; -import '../../../../model/item.dart'; -import '../../../../model/project.dart'; -import '../../../../utils/colors.dart'; -import '../../../../utils/time.dart'; +import '../../../utils/ext/string.dart'; +import '../../../models/item.dart'; +import '../../../models/project.dart'; +import '../../../utils/helper/theme.dart'; +import '../../../utils/ext/time.dart'; import 'new_entry.dart'; class ItemList extends StatefulWidget { @@ -69,7 +69,7 @@ class _ItemListState extends State { children: [ Expanded( child: Text( - daysElapsed(lastDate!).toUpperCase(), + lastDate!.daysElapsed().toUpperCase(), ), ), ], @@ -210,7 +210,7 @@ class _DynamicSyncState extends State { @override Widget build(BuildContext context) { - return Text("Last sync ${timeElapsed(widget.time)}"); + return Text("Last sync ${widget.time.timeElapsed()}"); } } @@ -249,7 +249,6 @@ class _SyncTileState extends State { @override Widget build(BuildContext context) { - print(isSyncing); return ListTile( subtitle: Text( "${widget.project.notSyncCount} changes to push", diff --git a/lib/components/pages/project/expenses/new_entry.dart b/lib/screens/project/expenses/new_entry.dart similarity index 96% rename from lib/components/pages/project/expenses/new_entry.dart rename to lib/screens/project/expenses/new_entry.dart index fc3b092..d63c75b 100644 --- a/lib/components/pages/project/expenses/new_entry.dart +++ b/lib/screens/project/expenses/new_entry.dart @@ -3,15 +3,15 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:select_form_field/select_form_field.dart'; -import 'package:splitr/model/connectors/local/item.dart'; +import 'package:splitr/data/local/item.dart'; -import '../../../../model/bill_data.dart'; -import '../../../../model/item.dart'; -import '../../../../model/participant.dart'; -import '../../../../model/project.dart'; -import '../../../../screens/new_screen.dart'; -import '../../../../utils/formatter/decimal.dart'; -import '../../../../utils/time.dart'; +import '../../../models/bill_data.dart'; +import '../../../models/item.dart'; +import '../../../models/participant.dart'; +import '../../../models/project.dart'; +import '../../../widgets/new_screen.dart'; +import '../../../utils/ext/text_input_formatter.dart'; +import '../../../utils/ext/time.dart'; import 'entry_table.dart'; class NewEntryPage extends StatelessWidget { @@ -70,7 +70,7 @@ class _NewEntrySubPageState extends State { void initState() { super.initState(); titleController.text = widget.bill.title; - dateController.text = daysElapsed(widget.bill.date); + dateController.text = widget.bill.date.daysElapsed(); emitterController.text = widget.bill.emitter.pseudo; amountController.text = widget.bill.amount.toStringAsFixed(2); @@ -207,7 +207,7 @@ class _NewEntrySubPageState extends State { lastDate: DateTime(2100), ); if (date != null) { - dateController.text = daysElapsed(date); + dateController.text = date.daysElapsed(); widget.bill.date = date; } }, diff --git a/lib/screens/project/new_project.dart b/lib/screens/project/new_project.dart new file mode 100644 index 0000000..704da8e --- /dev/null +++ b/lib/screens/project/new_project.dart @@ -0,0 +1,122 @@ +import 'package:flutter/material.dart'; +import 'package:pocketbase/pocketbase.dart'; + +import '../new_project/new_project_page.dart'; +import '../../main.dart'; +import '../../models/app_data.dart'; +import '../../data/pocketbase/provider.dart'; +import '../../data/provider.dart'; +import '../../models/instance.dart'; +import '../../models/project.dart'; +import '../../models/project_data.dart'; +import '../../widgets/new_screen.dart'; +import '../../utils/helper/random.dart'; + +class NewProjectScreen extends StatelessWidget { + NewProjectScreen({ + this.first = false, + this.project, + this.code, + this.instance, + super.key, + }); + + final bool first; + Project? project; + final String? code; + final Instance? instance; + + ProjectData setupData = ProjectData(); + + Future onValidate(context, formKey) async { + bool newProject = project == null; + + if (formKey.currentState != null && formKey.currentState!.validate()) { + if (newProject) { + project = Project( + name: setupData.projectName!, + code: setupData.join ? null : getRandom(5), + instance: setupData.instance!, + ); + } else { + project!.name = setupData.projectName!; + project!.provider = Provider.initFromInstance( + project!, + setupData.instance!, + ); + } + try { + AppData.current = project; + await project!.conn.save(); + if (setupData.join) { + await project!.provider.joinWithTitle(); + await project!.sync(); + } + } on ClientException catch (e) { + PocketBaseProvider.onClientException(e, context); + return; + } catch (e) { + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(e.toString()), + ), + ); + } + return; + } + if (first) { + AppData.firstRun = false; + runApp(const MainScreen()); + } else { + if (context.mounted) { + if (newProject) { + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (context) => NewProjectScreen( + project: project, + ), + ), + ); + } else { + if (Navigator.canPop(context)) { + Navigator.pop(context, true); + } else { + runApp(const MainScreen()); + } + } + } + } + } + } + + @override + Widget build(BuildContext context) { + setupData.instance = instance; + bool newProject = project == null; + + if (newProject && code != null) { + setupData.projectName = code; + setupData.join = true; + } + + return NewScreen( + title: first + ? 'Create your first project!' + : newProject + ? 'New project' + : 'Update project', + buttonTitle: first + ? 'Let\'s started' + : newProject + ? 'Create' + : 'Update', + child: NewProjectPage( + projectData: setupData, + project: project, + ), + onValidate: onValidate, + ); + } +} diff --git a/lib/components/pages/project/project_page.dart b/lib/screens/project/project_page.dart similarity index 97% rename from lib/components/pages/project/project_page.dart rename to lib/screens/project/project_page.dart index ede7862..d0ec82c 100644 --- a/lib/components/pages/project/project_page.dart +++ b/lib/screens/project/project_page.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_speed_dial/flutter_speed_dial.dart'; import 'package:share_plus/share_plus.dart'; -import 'package:splitr/utils/extenders/collections.dart'; +import 'package:splitr/utils/ext/list.dart'; -import '../../../model/project.dart'; -import '../../../screens/new_project_screen.dart'; +import '../../models/project.dart'; +import 'new_project.dart'; import '../projects_list/projects_list_page.dart'; import 'balances/balancing_page_part.dart'; import 'expenses/new_entry.dart'; diff --git a/lib/components/pages/projects_list/projects_list.dart b/lib/screens/projects_list/projects_list.dart similarity index 91% rename from lib/components/pages/projects_list/projects_list.dart rename to lib/screens/projects_list/projects_list.dart index 04a3d16..a24cf9b 100644 --- a/lib/components/pages/projects_list/projects_list.dart +++ b/lib/screens/projects_list/projects_list.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; -import 'package:splitr/model/connectors/local/project.dart'; -import 'package:splitr/utils/extenders/collections.dart'; +import 'package:splitr/data/local/project.dart'; +import 'package:splitr/utils/ext/list.dart'; +import 'package:splitr/utils/ext/set.dart'; -import '../../../model/app_data.dart'; -import '../../../model/project.dart'; -import '../../../screens/new_project_screen.dart'; -import '../../../utils/navigator/navigator.dart'; +import '../../models/app_data.dart'; +import '../../models/project.dart'; +import '../project/new_project.dart'; +import '../../utils/helper/navigator.dart'; import '../project/project_page.dart'; class ProjectsList extends StatefulWidget { diff --git a/lib/components/pages/projects_list/projects_list_page.dart b/lib/screens/projects_list/projects_list_page.dart similarity index 96% rename from lib/components/pages/projects_list/projects_list_page.dart rename to lib/screens/projects_list/projects_list_page.dart index 40acb33..05a0406 100644 --- a/lib/components/pages/projects_list/projects_list_page.dart +++ b/lib/screens/projects_list/projects_list_page.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../../../screens/new_project_screen.dart'; +import '../project/new_project.dart'; import 'projects_list.dart'; class ProjectsListPage extends StatefulWidget { diff --git a/lib/screens/setup_screen.dart b/lib/screens/setup_screen.dart deleted file mode 100644 index 3e85285..0000000 --- a/lib/screens/setup_screen.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:dynamic_color/dynamic_color.dart'; -import 'package:flutter/material.dart'; - -import 'main_screen.dart'; -import 'new_project_screen.dart'; - -class SetupScreen extends StatelessWidget { - const SetupScreen({super.key}); - - @override - Widget build(BuildContext context) { - return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) { - return MaterialApp( - title: 'Splitr', - theme: defaultTheme, - darkTheme: defaultDarkTheme, - themeMode: ThemeMode.system, - home: NewProjectScreen(first: true), - ); - }); - } -} diff --git a/lib/screens/splash_screen.dart b/lib/screens/splash_screen.dart deleted file mode 100644 index f727f5a..0000000 --- a/lib/screens/splash_screen.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:dynamic_color/dynamic_color.dart'; -import 'package:flutter/material.dart'; - -import 'main_screen.dart'; - -class SplashScreen extends StatelessWidget { - const SplashScreen({super.key}); - - @override - Widget build(BuildContext context) { - return DynamicColorBuilder(builder: (lightColorScheme, darkColorScheme) { - return MaterialApp( - theme: ThemeData( - colorScheme: lightColorScheme ?? defaultLightColorScheme, - useMaterial3: true, - ), - darkTheme: ThemeData( - colorScheme: darkColorScheme ?? defaultDarkColorScheme, - useMaterial3: true, - ), - home: const Scaffold( - body: Center( - child: Text("Starting up Splitr ..."), - ), - ), - ); - }); - } -} diff --git a/lib/db/splitr_database.dart b/lib/services/database.dart similarity index 89% rename from lib/db/splitr_database.dart rename to lib/services/database.dart index ca4dfae..5bbbd25 100644 --- a/lib/db/splitr_database.dart +++ b/lib/services/database.dart @@ -4,16 +4,16 @@ import 'dart:convert'; import 'package:path/path.dart'; import 'package:sqflite/sqflite.dart'; -import '../model/connectors/local/instance.dart'; -import '../model/connectors/local/item.dart'; -import '../model/connectors/local/item_part.dart'; -import '../model/connectors/local/participant.dart'; -import '../model/connectors/local/project.dart'; -import '../model/instance.dart'; -import '../model/item.dart'; -import '../model/item_part.dart'; -import '../model/participant.dart'; -import '../model/project.dart'; +import '../data/local/instance.dart'; +import '../data/local/item.dart'; +import '../data/local/item_part.dart'; +import '../data/local/participant.dart'; +import '../data/local/project.dart'; +import '../models/instance.dart'; +import '../models/item.dart'; +import '../models/item_part.dart'; +import '../models/participant.dart'; +import '../models/project.dart'; class SplitrDatabase { static final SplitrDatabase instance = SplitrDatabase._init(); diff --git a/lib/utils/extenders/datetime.dart b/lib/utils/ext/datetime.dart similarity index 99% rename from lib/utils/extenders/datetime.dart rename to lib/utils/ext/datetime.dart index 573f3e1..a25c82a 100644 --- a/lib/utils/extenders/datetime.dart +++ b/lib/utils/ext/datetime.dart @@ -1,3 +1,4 @@ + extension DateTimeExtension on DateTime { bool operator <(DateTime other) { return millisecondsSinceEpoch < other.millisecondsSinceEpoch; diff --git a/lib/utils/extenders/collections.dart b/lib/utils/ext/list.dart similarity index 67% rename from lib/utils/extenders/collections.dart rename to lib/utils/ext/list.dart index 5cf0e9d..1295204 100644 --- a/lib/utils/extenders/collections.dart +++ b/lib/utils/ext/list.dart @@ -1,4 +1,4 @@ -import '../../model/data.dart'; +import '../../models/data.dart'; extension ListExtension on List { void setPresence(bool presence, E element) { @@ -17,9 +17,3 @@ extension DataListExtension on List { return where((element) => !element.deleted); } } - -extension DataSetExtension on Set { - Iterable enabled() { - return where((element) => !element.deleted); - } -} diff --git a/lib/utils/ext/record_model.dart b/lib/utils/ext/record_model.dart new file mode 100644 index 0000000..d6ef572 --- /dev/null +++ b/lib/utils/ext/record_model.dart @@ -0,0 +1,7 @@ +import 'package:pocketbase/pocketbase.dart'; + +extension RecordModelExtension on RecordModel { + double? getDoubleOrNullValue(String fieldName) { + return getStringValue(fieldName).isEmpty ? null : getDoubleValue(fieldName); + } +} diff --git a/lib/utils/extenders/pocketbase.dart b/lib/utils/ext/record_service.dart similarity index 62% rename from lib/utils/extenders/pocketbase.dart rename to lib/utils/ext/record_service.dart index eeb0251..fd1ec9c 100644 --- a/lib/utils/extenders/pocketbase.dart +++ b/lib/utils/ext/record_service.dart @@ -1,11 +1,5 @@ import 'package:pocketbase/pocketbase.dart'; -extension RecordModelExtension on RecordModel { - double? getDoubleOrNullValue(String fieldName) { - return getStringValue(fieldName).isEmpty ? null : getDoubleValue(fieldName); - } -} - extension RecordServiceExtension on RecordService { Future updateOrCreate({ String? id, diff --git a/lib/utils/ext/set.dart b/lib/utils/ext/set.dart new file mode 100644 index 0000000..4f6f825 --- /dev/null +++ b/lib/utils/ext/set.dart @@ -0,0 +1,7 @@ +import '../../models/data.dart'; + +extension DataSetExtension on Set { + Iterable enabled() { + return where((element) => !element.deleted); + } +} diff --git a/lib/utils/extenders/string.dart b/lib/utils/ext/string.dart similarity index 100% rename from lib/utils/extenders/string.dart rename to lib/utils/ext/string.dart diff --git a/lib/utils/formatter/decimal.dart b/lib/utils/ext/text_input_formatter.dart similarity index 100% rename from lib/utils/formatter/decimal.dart rename to lib/utils/ext/text_input_formatter.dart diff --git a/lib/utils/ext/time.dart b/lib/utils/ext/time.dart new file mode 100644 index 0000000..d3a8ceb --- /dev/null +++ b/lib/utils/ext/time.dart @@ -0,0 +1,98 @@ +import 'package:intl/intl.dart'; + +String monthText(int month) { + return [ + '', + 'January', + 'Febuary', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'november', + 'december' + ][month]; +} + +extension DateExtension on DateTime { + static DateTime now = DateTime.now(); + String toDate() { + if (year != now.year) { + return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)} $year'; + } else { + return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)}'; + } + } + + String toPocketTime() { + return DateFormat('yyyy-MM-dd hh:mm:ss').format(this); + } + + String getFullDate() { + return "${day.toString().padLeft(2, '0')} ${monthText(month)} ${year.toString().padLeft(4, '0')}"; + } + + DateTime getDay() { + return DateTime(year, month, day); + } + + String daysElapsed() { + DateTime now = DateTime.now(); + + int delta = daysTo(now); + if (delta == 0) return 'today'; + if (delta == 1) return 'yesterday'; + if (delta == -1) return 'tomorrow'; + if (delta > -7 && delta < -1) return 'in ${-delta} days'; + if (delta < 7) return '$delta days ago'; + + if (year != now.year) { + return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)} $year'; + } else { + return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)}'; + } + } + +// https://stackoverflow.com/questions/52713115/flutter-find-the-number-of-days-between-two-dates + int daysSince(DateTime from) { + from = DateTime(from.year, from.month, from.day); + DateTime to = DateTime(year, month, day); + return (to.difference(from).inHours / 24).round(); + } + + int daysTo(DateTime to) { + DateTime from = DateTime(year, month, day); + to = DateTime(from.year, from.month, from.day); + return (to.difference(from).inHours / 24).round(); + } + + String timeElapsed() { + DateTime now = DateTime.now(); + + Duration difference = now.difference(this); + + if (difference.inDays > 7) { + if (year < now.year) { + return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)} $year'; + } else { + return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)}'; + } + } else if (difference.inDays > 0) { + return _plural('day', difference.inDays); + } else if (difference.inHours > 0) { + return _plural('hour', difference.inHours); + } else if (difference.inMinutes > 0) { + return _plural('minute', difference.inMinutes); + } else { + return _plural('second', difference.inSeconds); + } + } +} + +String _plural(String word, int amount) { + return '$amount $word${amount != 1 ? 's' : ''} ago'; +} diff --git a/lib/utils/dialogs/confirm_box.dart b/lib/utils/helper/confirm_box.dart similarity index 100% rename from lib/utils/dialogs/confirm_box.dart rename to lib/utils/helper/confirm_box.dart diff --git a/lib/utils/navigator/navigator.dart b/lib/utils/helper/navigator.dart similarity index 100% rename from lib/utils/navigator/navigator.dart rename to lib/utils/helper/navigator.dart diff --git a/lib/utils/helper/random.dart b/lib/utils/helper/random.dart new file mode 100644 index 0000000..ebf7ac4 --- /dev/null +++ b/lib/utils/helper/random.dart @@ -0,0 +1,14 @@ +import 'dart:math'; + +String getRandom(int length) { + const ch = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'; + Random r = Random(); + return String.fromCharCodes( + Iterable.generate( + length, + (_) => ch.codeUnitAt( + r.nextInt(ch.length), + ), + ), + ); +} diff --git a/lib/utils/colors.dart b/lib/utils/helper/theme.dart similarity index 57% rename from lib/utils/colors.dart rename to lib/utils/helper/theme.dart index 7118d78..b4b2fd1 100644 --- a/lib/utils/colors.dart +++ b/lib/utils/helper/theme.dart @@ -1,5 +1,32 @@ import 'package:flutter/material.dart'; +final defaultLightColorScheme = ColorScheme.fromSwatch( + primarySwatch: Colors.red, +); + +final defaultDarkColorScheme = ColorScheme.fromSwatch( + primarySwatch: ColorModel.red, + primaryColorDark: Colors.red, + brightness: Brightness.dark, + backgroundColor: Colors.black87, +); + +final defaultTheme = ThemeData( + colorScheme: defaultLightColorScheme, + brightness: Brightness.light, + useMaterial3: true, + appBarTheme: AppBarTheme(backgroundColor: defaultDarkColorScheme.primary), + inputDecorationTheme: const InputDecorationTheme( + border: OutlineInputBorder(), + )); + +final defaultDarkTheme = ThemeData( + useMaterial3: true, + brightness: Brightness.dark, + colorScheme: defaultDarkColorScheme, + appBarTheme: AppBarTheme(backgroundColor: defaultDarkColorScheme.primary), +); + class ColorModel { static Color primary = const Color(0xff992722); static Color secondary = const Color(0xff229399); diff --git a/lib/utils/time.dart b/lib/utils/time.dart deleted file mode 100644 index f45aadc..0000000 --- a/lib/utils/time.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'package:intl/intl.dart'; - -String monthText(int month) { - return [ - '', - 'January', - 'Febuary', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'november', - 'december' - ][month]; -} - -String getFullDate(DateTime dateTime) { - return "${dateTime.day.toString().padLeft(2, '0')} ${monthText(dateTime.month)} ${dateTime.year.toString().padLeft(4, '0')}"; -} - -DateTime getDay(DateTime dateTime) { - return DateTime(dateTime.year, dateTime.month, dateTime.day); -} - -String daysElapsed(DateTime dateTime) { - DateTime now = DateTime.now(); - - int delta = daysBetween(dateTime, now); - if (delta == 0) return 'today'; - if (delta == 1) return 'yesterday'; - if (delta == -1) return 'tomorrow'; - if (delta > -7 && delta < -1) return 'in ${-delta} days'; - if (delta < 7) return '$delta days ago'; - - if (dateTime.year != now.year) { - return '${dateTime.day}${dateTime.day == 1 ? 'st' : 'th'} ${monthText(dateTime.month)} ${dateTime.year}'; - } else { - return '${dateTime.day}${dateTime.day == 1 ? 'st' : 'th'} ${monthText(dateTime.month)}'; - } -} - -extension DateExtension on DateTime { - static DateTime now = DateTime.now(); - String toDate() { - if (year != now.year) { - return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)} $year'; - } else { - return '$day${day == 1 ? 'st' : 'th'} ${monthText(month)}'; - } - } - - String toPocketTime() { - return DateFormat('yyyy-MM-dd hh:mm:ss').format(this); - } -} - -DateTime fromPocketTime(String s) { - // return DateFormat("yyyy-MM-dd hh:mm:ss").parse(s, true); - return DateTime.parse(s); -} - -// https://stackoverflow.com/questions/52713115/flutter-find-the-number-of-days-between-two-dates -int daysBetween(DateTime from, DateTime to) { - from = DateTime(from.year, from.month, from.day); - to = DateTime(to.year, to.month, to.day); - return (to.difference(from).inHours / 24).round(); -} - -String _plural(String word, int amount) { - return '$amount $word${amount != 1 ? 's' : ''} ago'; -} - -String timeElapsed(DateTime dateTime) { - DateTime now = DateTime.now(); - - Duration difference = now.difference(dateTime); - - if (difference.inDays > 7) { - if (dateTime.year < now.year) { - return '${dateTime.day}${dateTime.day == 1 ? 'st' : 'th'} ${monthText(dateTime.month)} ${dateTime.year}'; - } else { - return '${dateTime.day}${dateTime.day == 1 ? 'st' : 'th'} ${monthText(dateTime.month)}'; - } - } else if (difference.inDays > 0) { - return _plural('day', difference.inDays); - } else if (difference.inHours > 0) { - return _plural('hour', difference.inHours); - } else if (difference.inMinutes > 0) { - return _plural('minute', difference.inMinutes); - } else { - return _plural('second', difference.inSeconds); - } -} diff --git a/lib/utils/tiles/header_tile.dart b/lib/widgets/header_tile.dart similarity index 100% rename from lib/utils/tiles/header_tile.dart rename to lib/widgets/header_tile.dart diff --git a/lib/screens/new_screen.dart b/lib/widgets/new_screen.dart similarity index 100% rename from lib/screens/new_screen.dart rename to lib/widgets/new_screen.dart diff --git a/lib/utils/switches/text_switch.dart b/lib/widgets/text_switch.dart similarity index 100% rename from lib/utils/switches/text_switch.dart rename to lib/widgets/text_switch.dart