Skip to content

Commit

Permalink
rfac,chor: bump dependencies and minor refactors
Browse files Browse the repository at this point in the history
Signed-off-by: Aman <[email protected]>
  • Loading branch information
aman-singh7 committed Oct 2, 2022
1 parent e4c5302 commit 8456020
Show file tree
Hide file tree
Showing 31 changed files with 479 additions and 363 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 32
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
8 changes: 7 additions & 1 deletion lib/data/services/local/image_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class ImageService {
cropStyle: CropStyle.circle,
compressFormat: ImageCompressFormat.png,
);
return croppedImage;

File? file;
if (croppedImage != null) {
file = File(croppedImage.path);
}

return file;
}
}
4 changes: 2 additions & 2 deletions lib/data/services/local/storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ class StorageService {
}
}

static set filter(ContestFilter? _filter) =>
_set(AppStrings.filterKey, json.encode(_filter!.toJson()));
static set filter(ContestFilter? filter) =>
_set(AppStrings.filterKey, json.encode(filter!.toJson()));
}
11 changes: 5 additions & 6 deletions lib/data/services/remote/notification_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: depend_on_referenced_packages

import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
import 'package:timezone/data/latest.dart' as tz;
Expand All @@ -13,20 +15,17 @@ class NotificationService {
'channelName',
importance: Importance.max,
),
iOS: IOSNotificationDetails(),
iOS: DarwinNotificationDetails(),
);
}

static Future init() async {
const settings = InitializationSettings(
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
iOS: IOSInitializationSettings(),
iOS: DarwinInitializationSettings(),
);

await _notification.initialize(
settings,
onSelectNotification: (payload) {},
);
await _notification.initialize(settings);

tz.initializeTimeZones();
final locationName = await FlutterNativeTimezone.getLocalTimezone();
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/models/grouped_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
part 'grouped_feed.freezed.dart';
part 'grouped_feed.g.dart';

@freezed
@Freezed(makeCollectionsUnmodifiable: false)
class GroupedFeed with _$GroupedFeed {
factory GroupedFeed({
required String username,
Expand Down
1 change: 0 additions & 1 deletion lib/domain/models/sign_up.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import 'handle.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/domain/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ class UserRepository {
headers: headers,
);

final _users = <User>[];
final users = <User>[];
if (response['status_code'] == 200) {
for (final user in response['data'] ?? []) {
_users.add(User.fromJson(user));
users.add(User.fromJson(user));
}
}

return _users;
return users;
}

/// Get a list the names of recognized institutes.
Expand Down
24 changes: 17 additions & 7 deletions lib/presentation/components/widgets/primary_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import '../../../data/constants/styles.dart';
class PrimaryButton extends StatelessWidget {
const PrimaryButton({
required this.label,
this.isLoading = false,
this.onPressed,
Key? key,
}) : super(key: key);
final String label;
final bool isLoading;
final VoidCallback? onPressed;

@override
Expand All @@ -28,13 +30,21 @@ class PrimaryButton extends StatelessWidget {
alignment: Alignment.center,
height: 48.r,
padding: EdgeInsets.symmetric(horizontal: 40.r),
child: Text(
label,
style: AppStyles.h6.copyWith(
color: AppColors.white,
fontWeight: FontWeight.w700,
),
),
child: isLoading
? SizedBox(
width: 20.r,
height: 20.r,
child: const CircularProgressIndicator(
color: AppColors.white,
),
)
: Text(
label,
style: AppStyles.h6.copyWith(
color: AppColors.white,
fontWeight: FontWeight.w700,
),
),
),
);
}
Expand Down
32 changes: 16 additions & 16 deletions lib/presentation/contests/bloc/contests_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,33 +159,33 @@ extension on ContestFilter {

if (!platfromCheck) return platfromCheck;

Duration _maxDuration;
Duration maxDuration;
switch (duration) {
case 0:
_maxDuration = const Duration(hours: 2);
maxDuration = const Duration(hours: 2);
break;
case 1:
_maxDuration = const Duration(hours: 3);
maxDuration = const Duration(hours: 3);
break;
case 2:
_maxDuration = const Duration(hours: 5);
maxDuration = const Duration(hours: 5);
break;
case 3:
_maxDuration = const Duration(days: 1);
maxDuration = const Duration(days: 1);
break;
case 4:
_maxDuration = const Duration(days: 10);
maxDuration = const Duration(days: 10);
break;
case 5:
_maxDuration = const Duration(days: 31);
maxDuration = const Duration(days: 31);
break;
default:
_maxDuration = Duration(days: 1e5.toInt());
maxDuration = Duration(days: 1e5.toInt());
}

final durationCheck = upcoming != null
? upcoming.compareDuration(_maxDuration)
: ongoing!.compareDuration(_maxDuration);
? upcoming.compareDuration(maxDuration)
: ongoing!.compareDuration(maxDuration);

if (!durationCheck) return durationCheck;

Expand All @@ -200,17 +200,17 @@ extension on ContestFilter {
}

extension on Upcoming {
bool compareDuration(Duration _duration) {
return _duration.compareTo(endTime.difference(startTime)) >= 0;
bool compareDuration(Duration duration) {
return duration.compareTo(endTime.difference(startTime)) >= 0;
}

bool compareStart(DateTime _startDate) {
return startTime.isAfter(_startDate);
bool compareStart(DateTime startDate) {
return startTime.isAfter(startDate);
}
}

extension on Ongoing {
bool compareDuration(Duration _duration) {
return _duration.compareTo(endTime.difference(DateTime.now())) >= 0;
bool compareDuration(Duration duration) {
return duration.compareTo(endTime.difference(DateTime.now())) >= 0;
}
}
8 changes: 4 additions & 4 deletions lib/presentation/contests/widgets/contest_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ContestCard extends StatelessWidget {
builder: (context, value, _) {
return IconButton(
onPressed: () {
final _bloc = context.read<ContestsBloc>();
final bloc = context.read<ContestsBloc>();
showDialog(
context: context,
builder: (context) {
Expand Down Expand Up @@ -208,7 +208,7 @@ class ContestCard extends StatelessWidget {
TextButton(
onPressed: () {
_notifier.value = false;
_bloc.pendingNotification
bloc.pendingNotification
.remove(upcoming!.name);

NotificationService.cancelNotification(
Expand All @@ -234,9 +234,9 @@ class ContestCard extends StatelessWidget {
onPressed: () {
if (upcoming != null) {
_notifier.value = true;
if (!_bloc.pendingNotification
if (!bloc.pendingNotification
.contains(upcoming!.name)) {
_bloc.pendingNotification
bloc.pendingNotification
.add(upcoming!.name);
}
NotificationService.setNotification(
Expand Down
10 changes: 5 additions & 5 deletions lib/presentation/contests/widgets/filter_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ class FilterSheet extends StatelessWidget {
divisions: 6,
value: state.duration!.toDouble(),
label: PlatformUtil.getLabel(state.duration),
onChanged: (_value) {
onChanged: (value) {
context
.read<ContestsBloc>()
.add(UpdateFilter(duration: _value.toInt()));
.add(UpdateFilter(duration: value.toInt()));
},
onChangeEnd: (_value) {
onChangeEnd: (value) {
context.read<ContestsBloc>().add(
UpdateFilter(
duration: _value.toInt(),
duration: value.toInt(),
updatedFilter: state.filter!.copyWith(
duration: _value.toInt(),
duration: value.toInt(),
),
),
);
Expand Down
6 changes: 3 additions & 3 deletions lib/presentation/core/main_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

import '../../data/constants/routes.dart';
import '../../data/constants/strings.dart';
import '../../data/constants/styles.dart';
import '../../data/services/local/image_service.dart';
import '../../data/services/local/storage_service.dart';
Expand All @@ -21,10 +22,9 @@ class Codephile extends StatelessWidget {
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(360, 640),
builder: () {
builder: (context, _) {
return GetMaterialApp(
builder: (context, widget) {
ScreenUtil.setContext(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
child: widget!,
Expand All @@ -50,7 +50,7 @@ class Codephile extends StatelessWidget {
StorageService.init();
NotificationService.init();

if (StorageService.user != null) {
if (StorageService.exists(AppStrings.userKey)) {
// Fetch User Details on Startup
try {
StorageService.user = await UserRepository.fetchUserDetails();
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/login/bloc/login_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:get/get.dart';

Expand Down
1 change: 0 additions & 1 deletion lib/presentation/login/widgets/text_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class PasswordField extends StatelessWidget {
horizontal: 8.r,
vertical: 10.r,
),
// TODO(BURG3R5): Deal with Focus transfer.
child: const ImageIcon(
Svg(AppAssets.lock),
),
Expand Down
44 changes: 22 additions & 22 deletions lib/presentation/profile/bloc/profile_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,43 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
_user = await UserRepository.fetchUserDetails(uid: event.userId);
}

SubmissionStatus? _subStats;
List<ActivityDetails>? _activityDetails;
SubmissionStatus? subStats;
List<ActivityDetails>? activityDetails;
// TODO(aman-singh7): Throw specific Error
try {
if (_user == null) throw Exception('User not found!!');
_followingList = await UserRepository.getFollowingList();

_subStats = await UserRepository.getSubmissionStatusData(_user!.id!);
subStats = await UserRepository.getSubmissionStatusData(_user!.id!);

_activityDetails = await UserRepository.getActivityDetails(_user!.id!);
activityDetails = await UserRepository.getActivityDetails(_user!.id!);
} on Exception catch (_) {
emit(state.copyWith(status: const Status.error(AppStrings.genericError)));
return;
}

for (final activity in _activityDetails ?? <ActivityDetails>[]) {
for (final activity in activityDetails ?? <ActivityDetails>[]) {
if (activity.createdAt == null) continue;
_activity[activity.createdAt!] = activity.correct;
}

bool? _isFollowing;
bool? isFollowing;
for (final follower in _followingList ?? <Following>[]) {
if (follower.id == event.userId) {
_isFollowing = true;
isFollowing = true;
break;
}
}

_isFollowing ??= false;
isFollowing ??= false;

emit(state.copyWith(
status: const Status(),
user: _user,
following: _followingList,
submissionStatus: _subStats,
submissionStatus: subStats,
personalProfile: isSelfProfile,
isFollowing: _isFollowing,
isFollowing: isFollowing,
currentYear: _currentYear,
currentTriplet: _currentTriplet,
showFollowing: false,
Expand Down Expand Up @@ -126,14 +126,14 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
throw Exception(AppStrings.genericError);
}

var _tempUser = StorageService.user;
_tempUser = _tempUser?.copyWith(
noOfFollowing: (_tempUser.noOfFollowing ?? 0) + 1,
var tempUser = StorageService.user;
tempUser = tempUser?.copyWith(
noOfFollowing: (tempUser.noOfFollowing ?? 0) + 1,
);
StorageService.user = _tempUser;
if (_user?.id != _tempUser?.id) return;
StorageService.user = tempUser;
if (_user?.id != tempUser?.id) return;

_user = _tempUser;
_user = tempUser;
}

Future unfollow(String userId) async {
Expand All @@ -143,14 +143,14 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
throw Exception(AppStrings.genericError);
}

var _tempUser = StorageService.user;
_tempUser = _tempUser?.copyWith(
noOfFollowing: (_tempUser.noOfFollowing ?? 0) - 1,
var tempUser = StorageService.user;
tempUser = tempUser?.copyWith(
noOfFollowing: (tempUser.noOfFollowing ?? 0) - 1,
);
StorageService.user = _tempUser;
if (_user?.id != _tempUser?.id) return;
StorageService.user = tempUser;
if (_user?.id != tempUser?.id) return;

_user = _tempUser;
_user = tempUser;
}

// Index -> Index%4
Expand Down
Loading

0 comments on commit 8456020

Please sign in to comment.