Skip to content

Commit 87886d3

Browse files
committed
bfix,chor: fix test and requested changes
Signed-off-by: Aman <aman2@me.iitr.ac.in>
1 parent f11b4e2 commit 87886d3

5 files changed

Lines changed: 14 additions & 16 deletions

File tree

lib/data/services/local/storage_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class StorageService {
5151
/// Currently logged in user.
5252
static User? get user {
5353
try {
54-
return User.fromJson(json.decode(_get<String>(AppStrings.userKey)!));
55-
} on Exception catch (_) {
54+
return User.fromJson(json.decode(_get<String>(AppStrings.userKey) ?? ''));
55+
} on FormatException catch (_) {
5656
// This just means that the user has not been stored previously.
5757
return null;
5858
}

lib/presentation/core/main_app.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../../data/constants/styles.dart';
88
import '../../data/services/local/image_service.dart';
99
import '../../data/services/local/storage_service.dart';
1010
import '../../data/services/remote/api_service.dart';
11+
import '../../domain/repositories/user_repository.dart';
1112
import 'navigation_observer.dart';
1213
import 'router.dart';
1314

@@ -47,6 +48,16 @@ class Codephile extends StatelessWidget {
4748
ImageService.init();
4849
StorageService.init();
4950

51+
if (StorageService.user != null) {
52+
// Fetch User Details on Startup
53+
try {
54+
StorageService.user = await UserRepository.fetchUserDetails();
55+
} on Exception catch (err) {
56+
debugPrint(err.toString());
57+
rethrow;
58+
}
59+
}
60+
5061
return const Codephile();
5162
}
5263
}

lib/presentation/home/bloc/home_bloc.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import 'package:flutter/widgets.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:freezed_annotation/freezed_annotation.dart';
55

6-
import '../../../data/services/local/storage_service.dart';
7-
import '../../../domain/repositories/user_repository.dart';
86
import '../../contests/contests_screen.dart';
97
import '../../feed/feed_screen.dart';
108
import '../../profile/profile_screen.dart';
@@ -20,20 +18,13 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
2018
}
2119
late final List<Widget> screens;
2220

23-
void init() async {
21+
void init() {
2422
screens = <Widget>[
2523
const FeedScreen(),
2624
const ContestsScreen(),
2725
const SearchScreen(),
2826
const ProfileScreen(),
2927
];
30-
// Fetch User Details on Startup
31-
try {
32-
StorageService.user = await UserRepository.fetchUserDetails();
33-
} on Exception catch (err) {
34-
debugPrint(err.toString());
35-
rethrow;
36-
}
3728
}
3829

3930
void _changeScreen(BottomNavItemPressed event, Emitter<HomeState> emit) {

lib/presentation/profile/widgets/submission_display.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ class SubmissionData {
141141
final String submissionType;
142142
final int value;
143143
final String key;
144-
}
145144

146-
extension on SubmissionData {
147145
double percentage(int total) {
148146
return double.parse((value * 100 / total).toStringAsFixed(1));
149147
}

lib/presentation/update_profile/widgets/profile_details.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ProfileDetails extends StatelessWidget {
2525
builder: (context, state) {
2626
return TextInput(
2727
controller: UpdateProfileBloc.controllers['name'],
28-
onChanged: (val) {},
2928
hint: 'Name',
3029
errorText: state.errors['name'],
3130
);
@@ -36,7 +35,6 @@ class ProfileDetails extends StatelessWidget {
3635
builder: (context, state) {
3736
return TextInput(
3837
controller: UpdateProfileBloc.controllers['username'],
39-
onChanged: (val) {},
4038
hint: 'Username',
4139
errorText: state.errors['username'],
4240
);

0 commit comments

Comments
 (0)