From 63b01d5cb33ea7628620c9a3adf6f84bbfc4d028 Mon Sep 17 00:00:00 2001 From: Banghua Zhao Date: Sat, 16 Nov 2024 11:23:22 +1300 Subject: [PATCH] Refactor Project structure (#41) --- lib/{ => app}/injection_container.dart | 2 +- lib/{ => app}/main.dart | 2 +- lib/presentation/bottom_navigator.dart | 10 +++------- lib/presentation/chat/viewModels/chat_view_model.dart | 3 +++ lib/presentation/chat/views/chat_screen.dart | 5 +---- lib/presentation/settings/views/feature_flag_page.dart | 2 +- .../settings/views/forget_password_page.dart | 2 +- lib/presentation/settings/views/login_page.dart | 10 +++++----- lib/presentation/settings/views/settings_page.dart | 2 +- lib/presentation/settings/views/sigup_page.dart | 2 +- lib/presentation/settings/views/update_password.dart | 2 +- lib/presentation/settings/views/user_profile_page.dart | 2 +- 12 files changed, 20 insertions(+), 24 deletions(-) rename lib/{ => app}/injection_container.dart (98%) rename lib/{ => app}/main.dart (98%) diff --git a/lib/injection_container.dart b/lib/app/injection_container.dart similarity index 98% rename from lib/injection_container.dart rename to lib/app/injection_container.dart index 5a7fdb6..3b4f7e1 100644 --- a/lib/injection_container.dart +++ b/lib/app/injection_container.dart @@ -23,7 +23,7 @@ import 'package:swiftcomp/presentation/settings/viewModels/settings_view_model.d import 'package:swiftcomp/presentation/settings/viewModels/signup_view_model.dart'; import 'package:swiftcomp/presentation/settings/viewModels/update_password_view_model.dart'; import 'package:swiftcomp/presentation/settings/viewModels/user_profile_view_model.dart'; -import 'presentation/chat/viewModels/chat_view_model.dart'; +import '../presentation/chat/viewModels/chat_view_model.dart'; final sl = GetIt.instance; diff --git a/lib/main.dart b/lib/app/main.dart similarity index 98% rename from lib/main.dart rename to lib/app/main.dart index f694212..07c2a24 100644 --- a/lib/main.dart +++ b/lib/app/main.dart @@ -12,7 +12,7 @@ import 'package:swiftcomp/util/in_app_reviewer_helper.dart'; import 'package:swiftcomp/util/others.dart'; import 'package:app_tracking_transparency/app_tracking_transparency.dart'; -import 'presentation/bottom_navigator.dart'; +import '../presentation/bottom_navigator.dart'; import 'injection_container.dart'; void main() async { diff --git a/lib/presentation/bottom_navigator.dart b/lib/presentation/bottom_navigator.dart index 15d6456..83ba74a 100644 --- a/lib/presentation/bottom_navigator.dart +++ b/lib/presentation/bottom_navigator.dart @@ -28,16 +28,12 @@ class _BottomNavigatorState extends State { final chatViewModel = Provider.of(context); return Consumer( builder: (context, featureFlagProvider, _) { - bool isChatEnabled = featureFlagProvider.getFeatureFlag('Chat'); - if (!isChatEnabled && _currentIndex == 2) { - _currentIndex = 1; - } return Scaffold( body: PageView( controller: _controller, physics: const NeverScrollableScrollPhysics(), children: [ - if (isChatEnabled) ChatScreen(), + ChatScreen(), ToolPage(), SettingsPage() ], @@ -54,13 +50,13 @@ class _BottomNavigatorState extends State { setState(() { _currentIndex = index; }); - if (_currentIndex == 0 && isChatEnabled) { + if (_currentIndex == 0) { chatViewModel.checkAuthStatus(); } }, type: BottomNavigationBarType.fixed, items: [ - if (isChatEnabled) _bottomItem(Icons.chat, Icons.chat, "Chat"), + _bottomItem(Icons.chat, Icons.chat, "Chat"), _bottomItem(Icons.view_list, Icons.view_list, "Tools"), _bottomItem(Icons.more_horiz, Icons.more_horiz, "Settings"), ])); diff --git a/lib/presentation/chat/viewModels/chat_view_model.dart b/lib/presentation/chat/viewModels/chat_view_model.dart index ca2924e..ff583db 100644 --- a/lib/presentation/chat/viewModels/chat_view_model.dart +++ b/lib/presentation/chat/viewModels/chat_view_model.dart @@ -68,6 +68,9 @@ class ChatViewModel extends ChangeNotifier { Future checkAuthStatus() async { isLoggedIn = await _authUseCase.isLoggedIn(); print("isLoggedIn: $isLoggedIn"); + + // Temporarily set it to true for demonstration + isLoggedIn = true; notifyListeners(); } diff --git a/lib/presentation/chat/views/chat_screen.dart b/lib/presentation/chat/views/chat_screen.dart index 1069690..2641004 100644 --- a/lib/presentation/chat/views/chat_screen.dart +++ b/lib/presentation/chat/views/chat_screen.dart @@ -1,9 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:swiftcomp/presentation/settings/providers/feature_flag_provider.dart'; -import '../../../injection_container.dart'; -import '../../../main.dart'; import '../../settings/views/login_page.dart'; import '../viewModels/chat_view_model.dart'; import 'chat_message_list.dart'; @@ -43,7 +40,7 @@ class _ChatScreenState extends State String? result = await Navigator.push( context, MaterialPageRoute( - builder: (context) => const NewLoginPage())); + builder: (context) => const LoginPage())); if (result == "Log in Success") { await viewModel.checkAuthStatus(); } diff --git a/lib/presentation/settings/views/feature_flag_page.dart b/lib/presentation/settings/views/feature_flag_page.dart index 473741c..5db4d41 100644 --- a/lib/presentation/settings/views/feature_flag_page.dart +++ b/lib/presentation/settings/views/feature_flag_page.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import '../../../injection_container.dart'; +import '../../../app/injection_container.dart'; import '../viewModels/feature_flag_view_model.dart'; class FeatureFlagPage extends StatelessWidget { diff --git a/lib/presentation/settings/views/forget_password_page.dart b/lib/presentation/settings/views/forget_password_page.dart index 37f7c4f..71811af 100644 --- a/lib/presentation/settings/views/forget_password_page.dart +++ b/lib/presentation/settings/views/forget_password_page.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../widgets/login_button.dart'; import '../viewModels/forget_password_view_model.dart'; // Adjust the import path as necessary -import '../../../injection_container.dart'; // Import your service locator to inject dependencies +import '../../../app/injection_container.dart'; // Import your service locator to inject dependencies class ForgetPasswordPage extends StatefulWidget { @override diff --git a/lib/presentation/settings/views/login_page.dart b/lib/presentation/settings/views/login_page.dart index 6fdc476..ef7507f 100644 --- a/lib/presentation/settings/views/login_page.dart +++ b/lib/presentation/settings/views/login_page.dart @@ -4,18 +4,18 @@ import 'package:provider/provider.dart'; import 'package:swiftcomp/presentation/settings/views/sigup_page.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import '../../../../injection_container.dart'; +import '../../../app/injection_container.dart'; import '../viewModels/login_view_model.dart'; import 'forget_password_page.dart'; -class NewLoginPage extends StatefulWidget { - const NewLoginPage({Key? key}) : super(key: key); +class LoginPage extends StatefulWidget { + const LoginPage({Key? key}) : super(key: key); @override - State createState() => _LoginPageState(); + State createState() => _LoginPageState(); } -class _LoginPageState extends State { +class _LoginPageState extends State { final _formKey = GlobalKey(); String email = ''; String password = ''; diff --git a/lib/presentation/settings/views/settings_page.dart b/lib/presentation/settings/views/settings_page.dart index f1b3226..a0adf68 100644 --- a/lib/presentation/settings/views/settings_page.dart +++ b/lib/presentation/settings/views/settings_page.dart @@ -43,7 +43,7 @@ class _SettingsPageState extends State { String? result = await Navigator.push( context, MaterialPageRoute( - builder: (context) => const NewLoginPage(), + builder: (context) => const LoginPage(), ), ); if (result == "Log in Success") { diff --git a/lib/presentation/settings/views/sigup_page.dart b/lib/presentation/settings/views/sigup_page.dart index 06a9143..28308d8 100644 --- a/lib/presentation/settings/views/sigup_page.dart +++ b/lib/presentation/settings/views/sigup_page.dart @@ -2,7 +2,7 @@ import 'package:domain/entities/user.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import '../../../../injection_container.dart'; +import '../../../app/injection_container.dart'; import '../viewModels/signup_view_model.dart'; class SignupPage extends StatelessWidget { diff --git a/lib/presentation/settings/views/update_password.dart b/lib/presentation/settings/views/update_password.dart index ac43567..fb4c4cf 100644 --- a/lib/presentation/settings/views/update_password.dart +++ b/lib/presentation/settings/views/update_password.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:swiftcomp/presentation/settings/viewModels/update_password_view_model.dart'; -import '../../../injection_container.dart'; +import '../../../app/injection_container.dart'; import '../viewModels/user_profile_view_model.dart'; class UpdatePasswordPage extends StatefulWidget { diff --git a/lib/presentation/settings/views/user_profile_page.dart b/lib/presentation/settings/views/user_profile_page.dart index 6a5f90f..3c38fdc 100644 --- a/lib/presentation/settings/views/user_profile_page.dart +++ b/lib/presentation/settings/views/user_profile_page.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:swiftcomp/presentation/settings/views/update_name_page.dart'; import 'package:swiftcomp/presentation/settings/views/update_password.dart'; -import '../../../injection_container.dart'; +import '../../../app/injection_container.dart'; import '../viewModels/user_profile_view_model.dart'; class UserProfilePage extends StatelessWidget {