Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Linting issues #33

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ app.*.map.json
.fvm/
.fvmrc
.vscode/settings.json
devtools_options.yaml
40 changes: 34 additions & 6 deletions lib/common/data/repository/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Repository {
int perPage = 15,
int page = 1,
}) async {
final response = await dio.get(
final response = await dio.get<Map<String, dynamic>>(
'/events/$event/speakers',
queryParameters: {'per_page': perPage, 'page': page},
);
Expand All @@ -24,13 +24,20 @@ class Repository {
});
}

return SpeakerResponse.fromJson(response.data as Map<String, dynamic>).data;
if (response.data == null) {
throw Exception({
'statusCode': response.statusCode,
'body': 'Data is null',
});
}

return SpeakerResponse.fromJson(response.data!).data;
}

Future<List<Room>> fetchRooms({
required String event,
}) async {
final response = await dio.get(
final response = await dio.get<Map<String, dynamic>>(
'/events/$event/rooms',
);

Expand All @@ -41,15 +48,29 @@ class Repository {
});
}

return RoomResponse.fromJson(response.data as Map<String, dynamic>).data;
if (response.data == null) {
throw Exception({
'statusCode': response.statusCode,
'body': 'Data is null',
});
}

if (response.data == null) {
throw Exception({
'statusCode': response.statusCode,
'body': 'Data is null',
});
}

return RoomResponse.fromJson(response.data!).data;
}

Future<List<Session>> fetchSessions({
required String event,
int perPage = 20,
int page = 1,
}) async {
final response = await dio.get(
final response = await dio.get<Map<String, dynamic>>(
'/events/$event/sessions',
queryParameters: {'per_page': perPage, 'page': page},
);
Expand All @@ -61,6 +82,13 @@ class Repository {
});
}

return SessionResponse.fromJson(response.data as Map<String, dynamic>).data;
if (response.data == null) {
throw Exception({
'statusCode': response.statusCode,
'body': 'Data is null',
});
}

return SessionResponse.fromJson(response.data!).data;
}
}
1 change: 1 addition & 0 deletions lib/common/network/api_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract mixin class ApiHelper<T> {
if (response.statusCode.success) {
return true;
} else {
// ignore: only_throw_errors
throw DioExceptions;
}
}
Expand Down
59 changes: 23 additions & 36 deletions lib/common/network/dio_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,35 @@ import 'package:fluttercon/common/utils/constants/api_constants.dart';

class DioExceptions implements Exception {
DioExceptions.fromDioError(DioException dioException) {
switch (dioException.type) {
case DioExceptionType.cancel:
message = ApiConstants.cancelRequest;
case DioExceptionType.connectionTimeout:
message = ApiConstants.connectionTimeOut;
case DioExceptionType.receiveTimeout:
message = ApiConstants.receiveTimeOut;
case DioExceptionType.badResponse:
message = _handleError(
message = switch (dioException.type) {
DioExceptionType.cancel => ApiConstants.cancelRequest,
DioExceptionType.connectionTimeout => ApiConstants.connectionTimeOut,
DioExceptionType.receiveTimeout => ApiConstants.receiveTimeOut,
DioExceptionType.badResponse => _handleError(
dioException.response?.statusCode,
dioException.response?.data,
);
case DioExceptionType.sendTimeout:
message = ApiConstants.sendTimeOut;
case DioExceptionType.connectionError:
message = ApiConstants.socketException;
default:
message = ApiConstants.unknownError;
break;
}
),
DioExceptionType.sendTimeout => ApiConstants.sendTimeOut,
DioExceptionType.connectionError => ApiConstants.socketException,
DioExceptionType.badCertificate ||
DioExceptionType.unknown =>
ApiConstants.unknownError,
};
}

late String message;

String _handleError(int? statusCode, dynamic error) {
switch (statusCode) {
case 400:
return ApiConstants.badRequest;
case 401:
return ApiConstants.unauthorized;
case 403:
return ApiConstants.forbidden;
case 404:
return ApiConstants.notFound;
case 422:
return ApiConstants.duplicateEmail;
case 500:
return ApiConstants.internalServerError;
case 502:
return ApiConstants.badGateway;
default:
return ApiConstants.unknownError;
}
return switch (statusCode) {
400 => ApiConstants.badRequest,
401 => ApiConstants.unauthorized,
403 => ApiConstants.forbidden,
404 => ApiConstants.notFound,
422 => ApiConstants.duplicateEmail,
500 => ApiConstants.internalServerError,
502 => ApiConstants.badGateway,
_ => ApiConstants.unknownError
};
}

@override
Expand Down
8 changes: 6 additions & 2 deletions lib/common/network/dio_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import 'package:fluttercon/core/app_extension.dart';
class DioInterceptor extends Interceptor {
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final RequestOptions(:baseUrl, :path, :queryParameters) = options;
logger('====================START====================');
logger('HTTP method => ${options.method} ');
logger(
'Request => ${options.baseUrl}${options.path}${options.queryParameters.format}',
'Request => $baseUrl$path${queryParameters.format}',
);
logger('Header => ${options.headers}');
return super.onRequest(options, handler);
Expand All @@ -23,7 +24,10 @@ class DioInterceptor extends Interceptor {
}

@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
void onResponse(
Response<dynamic> response,
ResponseInterceptorHandler handler,
) {
logger('Response => StatusCode: ${response.statusCode}'); // Debug log
logger('Response => Body: ${response.data}'); // Debug log
return super.onResponse(response, handler);
Expand Down
33 changes: 27 additions & 6 deletions lib/common/repository/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Repository {
int perPage = 15,
int page = 1,
}) async {
final response = await dio.get(
final response = await dio.get<Map<String, dynamic>>(
'/events/$event/speakers',
queryParameters: {'per_page': perPage, 'page': page},
);
Expand All @@ -24,13 +24,20 @@ class Repository {
});
}

return SpeakerResponse.fromJson(response.data as Map<String, dynamic>).data;
if (response.data == null) {
throw Exception({
'statusCode': response.statusCode,
'body': 'Data is null',
});
}

return SpeakerResponse.fromJson(response.data!).data;
}

Future<List<Room>> fetchRooms({
required String event,
}) async {
final response = await dio.get(
final response = await dio.get<Map<String, dynamic>>(
'/events/$event/rooms',
);

Expand All @@ -41,15 +48,22 @@ class Repository {
});
}

return RoomResponse.fromJson(response.data as Map<String, dynamic>).data;
if (response.data == null) {
throw Exception({
'statusCode': response.statusCode,
'body': 'Data is null',
});
}

return RoomResponse.fromJson(response.data!).data;
}

Future<List<Session>> fetchSessions({
required String event,
int perPage = 20,
int page = 1,
}) async {
final response = await dio.get(
final response = await dio.get<Map<String, dynamic>>(
'/events/$event/sessions',
queryParameters: {'per_page': perPage, 'page': page},
);
Expand All @@ -61,6 +75,13 @@ class Repository {
});
}

return SessionResponse.fromJson(response.data as Map<String, dynamic>).data;
if (response.data == null) {
throw Exception({
'statusCode': response.statusCode,
'body': 'Data is null',
});
}

return SessionResponse.fromJson(response.data!).data;
}
}
15 changes: 5 additions & 10 deletions lib/common/utils/app_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ bool isDesktop = Platform.isWindows || Platform.isLinux || Platform.isMacOS;
bool isMobile = Platform.isAndroid || Platform.isIOS || Platform.isFuchsia;

String getThemeModeString(ThemeMode themeMode) {
switch (themeMode) {
case ThemeMode.light:
return 'Light';

case ThemeMode.dark:
return 'Dark';

default:
return 'System Theme';
}
return switch (themeMode) {
ThemeMode.light => 'Light',
ThemeMode.dark => 'Dark',
_ => 'System Theme'
};
}
14 changes: 7 additions & 7 deletions lib/common/widgets/bottom_nav/bottom_nav_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import 'package:fluttercon/core/di/injectable.dart';
import 'package:fluttercon/core/local_storage.dart';
import 'package:fluttercon/core/theme/theme_colors.dart';

/// Custom Bottom Navigation Bar that will handles the page to be displayed on the dashboard
/// Custom Bottom Navigation Bar that will handles the page to be displayed on
/// the dashboard
class CustomBottomNavigationBar extends StatefulWidget {
const CustomBottomNavigationBar({
required this.selectedIndex,
Expand All @@ -15,7 +16,7 @@ class CustomBottomNavigationBar extends StatefulWidget {
});

final int selectedIndex;
final Function(int) onPageChange;
final void Function(int) onPageChange;
final List<PageItem> pages;

@override
Expand Down Expand Up @@ -64,18 +65,17 @@ class _CustomBottomNavigationBarState extends State<CustomBottomNavigationBar> {
}

// Handles double-tap to open the drawer
Future<void> _handleDoubleTap(BuildContext context) async {
void _handleDoubleTap(BuildContext context) {
if (widget.selectedIndex != 0) return;

if (bottomNavBarDoubleTapGestures == false) return;

final isDrawerOpen =
context.mounted ? Scaffold.of(context).isDrawerOpen : false;
final isDrawerOpen = Scaffold.of(context).isDrawerOpen;

if (isDrawerOpen) {
if (context.mounted) Scaffold.of(context).closeDrawer();
Scaffold.of(context).closeDrawer();
} else {
if (context.mounted) Scaffold.of(context).openDrawer();
Scaffold.of(context).openDrawer();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/common/widgets/text_scale_factor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TextScaleFactor extends StatelessWidget {
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
return MediaQuery(
data: mediaQuery.copyWith(textScaler: const TextScaler.linear(1)),
data: mediaQuery.copyWith(textScaler: TextScaler.noScaling),
child: child,
);
}
Expand Down
9 changes: 4 additions & 5 deletions lib/core/app_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';

extension StringExtension on String {
String get toCapital {
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
return '${this[0].toUpperCase()}${substring(1).toLowerCase()}';
}
}

Expand All @@ -17,14 +17,13 @@ extension IntegetExtension on int? {

extension GeneralExtension<T> on T {
bool get isEnum {
final split = toString().split('.');
return split.length > 1 && split[0] == runtimeType.toString();
return this is Enum;
}

String get getEnumString => toString().split('.').last.toCapital;
}

extension MapExtension on Map {
extension MapExtension<K, V> on Map<K, V> {
String get format {
if (isEmpty) {
return '';
Expand All @@ -36,7 +35,7 @@ extension MapExtension on Map {
}
}

//Helper functions
// Helper functions
void pop(BuildContext context, int returnedLevel) {
for (var i = 0; i < returnedLevel; ++i) {
Navigator.pop(context, true);
Expand Down
4 changes: 2 additions & 2 deletions lib/core/local_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class LocalStorage {
int getPrefInt(String settingsKey);
String getPrefString(String settingsKey);

void setPrefBool(String settingsKey, bool settingsValue);
void setPrefBool(String settingsKey, {required bool settingsValue});
void setPrefInt(String settingsKey, int settingsValue);
void setPrefString(String settingsKey, String settingsValue);

Expand Down Expand Up @@ -83,7 +83,7 @@ class LocalStorageImp implements LocalStorage {
}

@override
void setPrefBool(String settingsKey, bool settingsValue) {
void setPrefBool(String settingsKey, {required bool settingsValue}) {
if (!settingsValue) {
sharedPrefs.remove(settingsKey);
return;
Expand Down
Loading