1
0
mirror of https://github.com/Uttkarsh-raj/Plannerly.git synced 2024-11-24 08:02:18 +02:00

working and error screen added

This commit is contained in:
Uttkarsh-raj 2023-11-14 18:53:30 +05:30
parent 8a8babcfbf
commit 6979287ca4
20 changed files with 263 additions and 65 deletions

View File

@ -28,6 +28,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
on<HomeLogoutButtonClickedEvent>(homeLogoutButtonClickedEvent);
on<SearchForTasksEvent>(searchForTasksEvent);
on<HomeSearchButtonClickedEvent>(homeSearchButtonClickedEvent);
on<HomeLoginButtonClickedEvent>(homeLoginButtonClickedEvent);
}
FutureOr<void> homeInitialEvent(
@ -67,21 +68,16 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
);
}).toList();
} else {
emit(HomeUnableTofetchTasks(message: response["error"]));
emit(HomeLoadedErrorState(error: response["error"]));
}
} catch (e) {
emit(HomeUnableTofetchTasks(message: "Unable to get the data."));
log(e.toString());
}
try {
var res = await http.get(
res = await http.get(
Uri.parse("$baseUrl/tasks/regular"),
headers: {"token": token},
);
// print("res: ${res.body}");
var response = jsonDecode(res.body);
print("response: $response");
response = jsonDecode(res.body);
// print("response: $response");
if (response["success"]) {
List<dynamic> data = response["data"];
totalRegularTasks = response["total"];
@ -109,10 +105,10 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
name),
);
} else {
emit(HomeUnableTofetchTasks(message: response["error"]));
emit(HomeLoadedErrorState(error: response["error"]));
}
} catch (e) {
emit(HomeUnableTofetchTasks(message: "Unable to get the data."));
emit(HomeLoadedErrorState(error: e.toString()));
log(e.toString());
}
// emit(HomeLoadedSuccessState(regualarTasks, urgentTasks, totalUrgentTasks,
@ -296,4 +292,9 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
HomeSearchButtonClickedEvent event, Emitter<HomeState> emit) {
emit(HomeSearchButtonClickedState());
}
FutureOr<void> homeLoginButtonClickedEvent(
HomeLoginButtonClickedEvent event, Emitter<HomeState> emit) {
emit(HomeLoginButtonClickedState());
}
}

View File

@ -55,3 +55,5 @@ class SearchForTasksEvent extends HomeEvent {
SearchForTasksEvent({required this.searchString});
}
class HomeLoginButtonClickedEvent extends HomeEvent {}

View File

@ -31,7 +31,11 @@ class HomeLoadedSuccessState extends HomeState {
this.name);
}
class HomeLoadedErrorState extends HomeState {}
class HomeLoadedErrorState extends HomeState {
final String error;
HomeLoadedErrorState({required this.error});
}
class HomeErrorState extends HomeState {}
@ -76,3 +80,5 @@ class SearchErrorState extends HomeState {
}
class HomeSearchButtonClickedState extends HomeActionState {}
class HomeLoginButtonClickedState extends HomeActionState {}

View File

@ -35,10 +35,13 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
var response = jsonDecode(res.body);
if (res.statusCode == 200) {
SharedPreferences sp = await SharedPreferences.getInstance();
sp.setString('token', response['token']);
sp.setString('userId', response['user_id']);
sp.setString('token', response['data']['token']);
sp.setString('userId', response['data']['user_id']);
sp.setString(
'userName', response['first_name'] + " " + response['last_name']);
'userName',
response['data']['first_name'] +
" " +
response['data']['last_name']);
emit(LoginSuccessState());
} else {
emit(LoginLoadingErrorState(message: response['error']));

View File

@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:plannerly/screens/widgets/check_login.dart';
// import 'package:plannerly/models/local_notifications.dart';
import 'package:plannerly/view/widgets/check_login.dart';
void main() {
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// await LocalNotifications.init();
runApp(const MyApp());
}

View File

@ -0,0 +1,44 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class LocalNotifications {
static final FlutterLocalNotificationsPlugin _flutterLocalNotificationPlugin =
FlutterLocalNotificationsPlugin();
//initialize plugin
static Future init() async {
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
final DarwinInitializationSettings initializationSettingsDarwin =
DarwinInitializationSettings(
onDidReceiveLocalNotification: (id, title, body, payload) => null,
);
final LinuxInitializationSettings initializationSettingsLinux =
LinuxInitializationSettings(defaultActionName: 'Open notification');
final InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsDarwin,
linux: initializationSettingsLinux);
_flutterLocalNotificationPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: (details) => null,
);
}
//show simple notifications
static Future showSimpleNotification({
required String title,
required String body,
required String payload,
}) async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('your channel id', 'your channel name',
channelDescription: 'your channel description',
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker');
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await _flutterLocalNotificationPlugin
.show(0, title, body, notificationDetails, payload: payload);
}
}

View File

@ -1,14 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:plannerly/screens/home/home_loading.dart';
import 'package:plannerly/screens/login/login.dart';
import 'package:plannerly/screens/regular_tasks/regular_tasks_page.dart';
import 'package:plannerly/screens/search/search.dart';
import 'package:plannerly/screens/urgent_tasks/urgent_tasks_page.dart';
import 'package:plannerly/screens/widgets/custom_drawer.dart';
import 'package:plannerly/screens/widgets/form_field.dart';
import 'package:plannerly/screens/widgets/task.dart';
import 'package:plannerly/view/home/home_loading.dart';
import 'package:plannerly/view/login/login.dart';
import 'package:plannerly/view/regular_tasks/regular_tasks_page.dart';
import 'package:plannerly/view/search/search.dart';
import 'package:plannerly/view/urgent_tasks/urgent_tasks_page.dart';
import 'package:plannerly/view/widgets/custom_drawer.dart';
import 'package:plannerly/view/widgets/form_field.dart';
import 'package:plannerly/view/widgets/task.dart';
import 'package:plannerly/utils/colors/colors.dart';
import '../../bloc/home/home_bloc.dart';
@ -185,14 +184,15 @@ class _HomeScreenState extends State<HomeScreen> {
),
);
} else {
Fluttertoast.showToast(
msg: "Please provide information for all fields.",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: AppColors.grey,
textColor: AppColors.backgroundDark,
fontSize: 16.0,
);
// Fluttertoast.showToast(
// msg: "Please provide information for all fields.",
// toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.BOTTOM,
// backgroundColor: AppColors.grey,
// textColor: AppColors.backgroundDark,
// fontSize: 16.0,
// );//TODO: add a mssg of some sort
print('Plz fill the details fully');
}
},
child: const Text(
@ -227,6 +227,12 @@ class _HomeScreenState extends State<HomeScreen> {
builder: (context) => const SearchPage(),
),
);
} else if (state is HomeLoginButtonClickedState) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const LoginPage(),
),
);
}
},
builder: (context, state) {
@ -754,16 +760,63 @@ class _HomeScreenState extends State<HomeScreen> {
),
);
case HomeLoadedErrorState:
var s = state as HomeLoadedErrorState;
return Scaffold(
backgroundColor: AppColors.backgroundDark,
body: Center(
child: Text(
'Some error ocurred!',
style: TextStyle(
fontSize: 20,
color: AppColors.white.withOpacity(0.3),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.info_outline,
color: Colors.red[400],
),
const SizedBox(width: 10),
Text(
s.error,
style: TextStyle(
fontSize: 20,
color: AppColors.white.withOpacity(0.3),
),
),
],
),
),
),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"Please try to login again.",
style: TextStyle(
color: AppColors.white,
fontSize: 18,
fontWeight: FontWeight.w300,
),
),
TextButton(
onPressed: () {
homeBloc.add(HomeLoginButtonClickedEvent());
},
child: const Center(
child: Text(
"Login",
style: TextStyle(
decoration: TextDecoration.underline,
color: AppColors.buttonBlue,
fontSize: 18,
fontWeight: FontWeight.w400,
),
),
),
),
],
),
)
],
),
);
default:

View File

@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:plannerly/bloc/login/login_bloc.dart';
import 'package:plannerly/screens/home/home.dart';
import 'package:plannerly/screens/home/home_loading.dart';
import 'package:plannerly/screens/signup/signup.dart';
import 'package:plannerly/screens/widgets/form_field.dart';
import 'package:plannerly/view/home/home.dart';
import 'package:plannerly/view/home/home_loading.dart';
import 'package:plannerly/view/signup/signup.dart';
import 'package:plannerly/view/widgets/form_field.dart';
import 'package:plannerly/utils/colors/colors.dart';
class LoginPage extends StatefulWidget {

View File

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:plannerly/bloc/home/home_bloc.dart';
import 'package:plannerly/screens/home/home_loading.dart';
import 'package:plannerly/screens/widgets/task.dart';
import 'package:plannerly/view/home/home_loading.dart';
import 'package:plannerly/view/widgets/task.dart';
import 'package:plannerly/utils/colors/colors.dart';
class RegularTasks extends StatefulWidget {

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:plannerly/bloc/home/home_bloc.dart';
import 'package:plannerly/screens/widgets/task.dart';
import 'package:plannerly/view/widgets/task.dart';
import 'package:plannerly/utils/colors/colors.dart';
class SearchPage extends StatefulWidget {

View File

@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:plannerly/bloc/signup/signup_bloc.dart';
import 'package:plannerly/screens/home/home_loading.dart';
import 'package:plannerly/screens/login/login.dart';
import 'package:plannerly/screens/widgets/form_field.dart';
import 'package:plannerly/view/home/home_loading.dart';
import 'package:plannerly/view/login/login.dart';
import 'package:plannerly/view/widgets/form_field.dart';
import 'package:plannerly/utils/colors/colors.dart';
class SignUpPage extends StatefulWidget {

View File

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:plannerly/bloc/home/home_bloc.dart';
import 'package:plannerly/screens/home/home_loading.dart';
import 'package:plannerly/screens/widgets/task.dart';
import 'package:plannerly/view/home/home_loading.dart';
import 'package:plannerly/view/widgets/task.dart';
import 'package:plannerly/utils/colors/colors.dart';
class UrgentTasks extends StatefulWidget {

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:plannerly/screens/home/home.dart';
import 'package:plannerly/screens/login/login.dart';
import 'package:plannerly/view/home/home.dart';
import 'package:plannerly/view/login/login.dart';
import 'package:shared_preferences/shared_preferences.dart';
class MainAuth extends StatefulWidget {

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:plannerly/bloc/home/home_bloc.dart';
import 'package:plannerly/screens/home/home.dart';
import 'package:plannerly/view/home/home.dart';
import 'package:plannerly/utils/colors/colors.dart';
class CustomDrawer extends StatefulWidget {

View File

@ -5,8 +5,12 @@
import FlutterMacOS
import Foundation
import flutter_local_notifications
import flutter_timezone
import shared_preferences_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}

View File

@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: transitive
description:
name: args
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.4.2"
async:
dependency: transitive
description:
@ -57,6 +65,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.6"
dbus:
dependency: transitive
description:
name: dbus
sha256: "6f07cba3f7b3448d42d015bfd3d53fe12e5b36da2423f23838efc1d5fb31a263"
url: "https://pub.dev"
source: hosted
version: "0.7.8"
fake_async:
dependency: transitive
description:
@ -102,24 +118,48 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
flutter_local_notifications:
dependency: "direct main"
description:
name: flutter_local_notifications
sha256: "6d11ea777496061e583623aaf31923f93a9409ef8fcaeeefdd6cd78bf4fe5bb3"
url: "https://pub.dev"
source: hosted
version: "16.1.0"
flutter_local_notifications_linux:
dependency: transitive
description:
name: flutter_local_notifications_linux
sha256: "33f741ef47b5f63cc7f78fe75eeeac7e19f171ff3c3df054d84c1e38bedb6a03"
url: "https://pub.dev"
source: hosted
version: "4.0.0+1"
flutter_local_notifications_platform_interface:
dependency: transitive
description:
name: flutter_local_notifications_platform_interface
sha256: "7cf643d6d5022f3baed0be777b0662cce5919c0a7b86e700299f22dc4ae660ef"
url: "https://pub.dev"
source: hosted
version: "7.0.0+1"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_timezone:
dependency: "direct main"
description:
name: flutter_timezone
sha256: "06b35132c98fa188db3c4b654b7e1af7ccd01dfe12a004d58be423357605fb24"
url: "https://pub.dev"
source: hosted
version: "1.0.8"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
fluttertoast:
dependency: "direct main"
description:
name: fluttertoast
sha256: "474f7d506230897a3cd28c965ec21c5328ae5605fc9c400cd330e9e9d6ac175c"
url: "https://pub.dev"
source: hosted
version: "8.2.2"
http:
dependency: "direct main"
description:
@ -136,6 +176,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints:
dependency: transitive
description:
@ -216,6 +264,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.1"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
url: "https://pub.dev"
source: hosted
version: "5.4.0"
platform:
dependency: transitive
description:
@ -240,6 +296,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.5"
rxdart:
dependency: "direct main"
description:
name: rxdart
sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb"
url: "https://pub.dev"
source: hosted
version: "0.27.7"
shared_preferences:
dependency: "direct main"
description:
@ -349,6 +413,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.0"
timezone:
dependency: transitive
description:
name: timezone
sha256: "1cfd8ddc2d1cfd836bc93e67b9be88c3adaeca6f40a00ca999104c30693cdca0"
url: "https://pub.dev"
source: hosted
version: "0.9.2"
typed_data:
dependency: transitive
description:
@ -389,6 +461,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.3"
xml:
dependency: transitive
description:
name: xml
sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84"
url: "https://pub.dev"
source: hosted
version: "6.3.0"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.7.0"

View File

@ -38,9 +38,11 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
http: ^1.1.0
fluttertoast: ^8.2.2
loading_animation_widget: ^1.2.0+4
shared_preferences: ^2.2.2
rxdart: ^0.27.7
flutter_local_notifications: ^16.1.0
flutter_timezone: ^1.0.8
dev_dependencies:
flutter_test: