Skip to content

Commit

Permalink
Refactor Project structure (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
banghuazhao authored Nov 15, 2024
1 parent 9b93f3b commit 63b01d5
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart → lib/app/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 3 additions & 7 deletions lib/presentation/bottom_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ class _BottomNavigatorState extends State<BottomNavigator> {
final chatViewModel = Provider.of<ChatViewModel>(context);
return Consumer<FeatureFlagProvider>(
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()
],
Expand All @@ -54,13 +50,13 @@ class _BottomNavigatorState extends State<BottomNavigator> {
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"),
]));
Expand Down
3 changes: 3 additions & 0 deletions lib/presentation/chat/viewModels/chat_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class ChatViewModel extends ChangeNotifier {
Future<void> checkAuthStatus() async {
isLoggedIn = await _authUseCase.isLoggedIn();
print("isLoggedIn: $isLoggedIn");

// Temporarily set it to true for demonstration
isLoggedIn = true;
notifyListeners();
}

Expand Down
5 changes: 1 addition & 4 deletions lib/presentation/chat/views/chat_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -43,7 +40,7 @@ class _ChatScreenState extends State<ChatScreen>
String? result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const NewLoginPage()));
builder: (context) => const LoginPage()));
if (result == "Log in Success") {
await viewModel.checkAuthStatus();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/settings/views/feature_flag_page.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/settings/views/forget_password_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/presentation/settings/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NewLoginPage> createState() => _LoginPageState();
State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<NewLoginPage> {
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
String email = '';
String password = '';
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/settings/views/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class _SettingsPageState extends State<SettingsPage> {
String? result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const NewLoginPage(),
builder: (context) => const LoginPage(),
),
);
if (result == "Log in Success") {
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/settings/views/sigup_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/settings/views/update_password.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/settings/views/user_profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 63b01d5

Please sign in to comment.