Skip to content

Commit

Permalink
Fix Linting issues (#33)
Browse files Browse the repository at this point in the history
* linting fixes

* add devtools extension to git ignore

* dart format

* delete unused api_helper
  • Loading branch information
mboyamike authored Jul 29, 2024
1 parent 733771a commit 60606a0
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
- name: ⚙️ Code Generation
run: dart run build_runner build --delete-conflicting-outputs

# - name: 🕵️ Analyze
# run: flutter analyze lib
- name: 🕵️ Analyze
run: flutter analyze lib

# - name: ⚙️ Download Android keystore
# id: android_keystore
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
- name: ⚙️ Code Generation
run: dart run build_runner build --delete-conflicting-outputs

# - name: 🕵️ Analyze
# run: flutter analyze lib
- name: 🕵️ Analyze
run: flutter analyze lib

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;
}
}
33 changes: 0 additions & 33 deletions lib/common/network/api_helper.dart

This file was deleted.

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
Loading

0 comments on commit 60606a0

Please sign in to comment.