Skip to content

Commit

Permalink
fix: Fix flutter analyze (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-martinez authored and taorepoara committed Sep 29, 2023
1 parent e034f01 commit 3bbb069
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 46 deletions.
File renamed without changes.
5 changes: 3 additions & 2 deletions lib/api/response_models/build_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class BuildResponse extends ApiResponse {

BuildResponse.fromJson(Map<String, dynamic> json)
: id = json["id"],
status = BuildStatus.values
.firstWhere((e) => e.toString() == 'BuildStatus.' + json["status"], orElse: () => BuildStatus.failure),
status = BuildStatus.values.firstWhere(
(e) => e.toString() == 'BuildStatus.${json["status"]}',
orElse: () => BuildStatus.failure),
insertedAt = DateTime.parse(json["inserted_at"]),
buildNumber = json["build_number"];

Expand Down
25 changes: 17 additions & 8 deletions lib/api/user_api.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:client_common/api/lenra_http_client.dart';
import 'package:client_common/api/request_models/ask_code_lost_password_request.dart';
import 'package:client_common/api/request_models/change_password_request.dart';
import 'package:client_common/api/request_models/loginRequest.dart';
import 'package:client_common/api/request_models/login_request.dart';
import 'package:client_common/api/request_models/register_request.dart';
import 'package:client_common/api/request_models/send_code_lost_password_request.dart';
import 'package:client_common/api/request_models/validate_dev_request.dart';
Expand All @@ -10,25 +10,29 @@ import 'package:client_common/api/response_models/auth_response.dart';
import 'package:client_common/api/response_models/empty_response.dart';

class UserApi {
static Future<AuthResponse> register(RegisterRequest body) => LenraAuth.instance.post(
static Future<AuthResponse> register(RegisterRequest body) =>
LenraAuth.instance.post(
"/register",
body: body,
responseMapper: (json) => AuthResponse.fromJson(json),
);

static Future<AuthResponse> login(LoginRequest body) => LenraAuth.instance.post(
static Future<AuthResponse> login(LoginRequest body) =>
LenraAuth.instance.post(
"/login",
body: body,
responseMapper: (json) => AuthResponse.fromJson(json),
);

static Future<AuthResponse> validateUser(ValidateUserRequest body) => LenraAuth.instance.post(
static Future<AuthResponse> validateUser(ValidateUserRequest body) =>
LenraAuth.instance.post(
"/verify",
body: body,
responseMapper: (json) => AuthResponse.fromJson(json),
);

static Future<AuthResponse> validateDev(ValidateDevRequest body) => LenraApi.instance.put(
static Future<AuthResponse> validateDev(ValidateDevRequest body) =>
LenraApi.instance.put(
"/verify/dev",
body: body,
responseMapper: (json) => AuthResponse.fromJson(json),
Expand All @@ -43,19 +47,24 @@ class UserApi {
"/logout",
responseMapper: (json) => EmptyResponse.fromJson(json),
);
static Future<EmptyResponse> changePassword(ChangePasswordRequest body) => LenraApi.instance.put(
static Future<EmptyResponse> changePassword(ChangePasswordRequest body) =>
LenraApi.instance.put(
"/password",
body: body,
responseMapper: (json) => EmptyResponse.fromJson(json),
);

static Future<EmptyResponse> askCodeLostPassword(AskCodeLostPasswordRequest body) => LenraAuth.instance.post(
static Future<EmptyResponse> askCodeLostPassword(
AskCodeLostPasswordRequest body) =>
LenraAuth.instance.post(
"/password/lost",
body: body,
responseMapper: (json) => EmptyResponse.fromJson(json),
);

static Future<EmptyResponse> sendCodeLostPassword(SendCodeLostPasswordRequest body) => LenraAuth.instance.put(
static Future<EmptyResponse> sendCodeLostPassword(
SendCodeLostPasswordRequest body) =>
LenraAuth.instance.put(
"/password/lost",
body: body,
responseMapper: (json) => EmptyResponse.fromJson(json),
Expand Down
31 changes: 21 additions & 10 deletions lib/models/auth_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:client_common/api/lenra_http_client.dart';
import 'package:client_common/api/request_models/ask_code_lost_password_request.dart';
import 'package:client_common/api/request_models/change_password_request.dart';
import 'package:client_common/api/request_models/loginRequest.dart';
import 'package:client_common/api/request_models/login_request.dart';
import 'package:client_common/api/request_models/register_request.dart';
import 'package:client_common/api/request_models/send_code_lost_password_request.dart';
import 'package:client_common/api/request_models/validate_dev_request.dart';
Expand Down Expand Up @@ -49,13 +49,16 @@ class AuthModel extends ChangeNotifier {
}

Future<AuthResponse> register(String email, String password) async {
var res = await registerStatus.handle(() => UserApi.register(RegisterRequest(email, password)), notifyListeners);
var res = await registerStatus.handle(
() => UserApi.register(RegisterRequest(email, password)),
notifyListeners);
_handleAuthResponse(res);
return res;
}

Future<AuthResponse> login(String email, String password) async {
var res = await loginStatus.handle(() => UserApi.login(LoginRequest(email, password)), notifyListeners);
var res = await loginStatus.handle(
() => UserApi.login(LoginRequest(email, password)), notifyListeners);
_handleAuthResponse(res);
return res;
}
Expand All @@ -67,13 +70,15 @@ class AuthModel extends ChangeNotifier {
}

Future<AuthResponse> validateUser(String code) async {
var res = await validateUserStatus.handle(() => UserApi.validateUser(ValidateUserRequest(code)), notifyListeners);
var res = await validateUserStatus.handle(
() => UserApi.validateUser(ValidateUserRequest(code)), notifyListeners);
_handleAuthResponse(res);
return res;
}

Future<AuthResponse> validateDev(String code) async {
var res = await validateDevStatus.handle(() => UserApi.validateDev(ValidateDevRequest(code)), notifyListeners);
var res = await validateDevStatus.handle(
() => UserApi.validateDev(ValidateDevRequest(code)), notifyListeners);
_handleAuthResponse(res);
return res;
}
Expand All @@ -88,22 +93,28 @@ class AuthModel extends ChangeNotifier {

Future<EmptyResponse> askCodeLostPassword(String email) async {
var res = await askCodeLostPasswordStatus.handle(
() => UserApi.askCodeLostPassword(AskCodeLostPasswordRequest(email)), notifyListeners);
() => UserApi.askCodeLostPassword(AskCodeLostPasswordRequest(email)),
notifyListeners);
notifyListeners();
return res;
}

Future<EmptyResponse> sendCodeLostPassword(String code, String email, String password, String confirmation) async {
Future<EmptyResponse> sendCodeLostPassword(
String code, String email, String password, String confirmation) async {
var res = await sendCodeLostPasswordStatus.handle(
() => UserApi.sendCodeLostPassword(SendCodeLostPasswordRequest(code, email, password, confirmation)),
() => UserApi.sendCodeLostPassword(
SendCodeLostPasswordRequest(code, email, password, confirmation)),
notifyListeners);
notifyListeners();
return res;
}

Future<EmptyResponse> changePassword(String old, String password, String confirmation) async {
Future<EmptyResponse> changePassword(
String old, String password, String confirmation) async {
var res = await changePasswordStatus.handle(
() => UserApi.changePassword(ChangePasswordRequest(old, password, confirmation)), notifyListeners);
() => UserApi.changePassword(
ChangePasswordRequest(old, password, confirmation)),
notifyListeners);
notifyListeners();
return res;
}
Expand Down
17 changes: 11 additions & 6 deletions lib/models/user_application_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class UserApplicationModel extends ChangeNotifier {
String? currentApp;

Future<List<AppResponse>> fetchUserApplications() async {
var res = await fetchApplicationsStatus.handle(ApplicationApi.getUserApps, notifyListeners);
this.userApps = res.apps;
var res = await fetchApplicationsStatus.handle(
ApplicationApi.getUserApps, notifyListeners);
userApps = res.apps;
notifyListeners();
return res.apps;
}
Expand All @@ -55,7 +56,8 @@ class UserApplicationModel extends ChangeNotifier {
}

Future<UpdateAppResponse> updateApp(UpdateAppRequest body) async {
var res = await updateApplicationStatus.handle(() => ApplicationApi.updateApp(body), notifyListeners);
var res = await updateApplicationStatus.handle(
() => ApplicationApi.updateApp(body), notifyListeners);
notifyListeners();
return res;
}
Expand All @@ -70,7 +72,8 @@ class UserApplicationModel extends ChangeNotifier {
return res;
}

Future<UpdateEnvironmentResponse> updateEnvironment(int appId, int envId, UpdateEnvironmentRequest body) async {
Future<UpdateEnvironmentResponse> updateEnvironment(
int appId, int envId, UpdateEnvironmentRequest body) async {
var res = await updateEnvironmentStatus.handle(
() => EnvironmentApi.updateEnvironment(appId, envId, body),
notifyListeners,
Expand All @@ -86,15 +89,17 @@ class UserApplicationModel extends ChangeNotifier {
CreateEnvironmentUserAccessRequest body,
) async {
var res = await inviteUserStatus.handle(
() => EnvironmentUserAccessApi.createEnvironmentUserAccess(appId, envId, body),
() => EnvironmentUserAccessApi.createEnvironmentUserAccess(
appId, envId, body),
notifyListeners,
);

notifyListeners();
return res;
}

Future<EnvironmentUserAccessesResponse> getInvitedUsers(int appId, int envId) async {
Future<EnvironmentUserAccessesResponse> getInvitedUsers(
int appId, int envId) async {
var res = await getInvitedUsersStatus.handle(
() => EnvironmentUserAccessApi.getEnvironmentUserAccesses(appId, envId),
notifyListeners,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/color_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/painting.dart';

extension ColorParser on String {
Color parseColor() {
String hex = this.replaceFirst('#', '');
String hex = replaceFirst('#', '');
int hexb16 = int.parse('FF$hex', radix: 16);
return Color(hexb16);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/connexion_utils_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ PhoenixSocket createPhoenixSocket(
String endpoint,
Map<String, String> params,
) =>
new PhoenixSocket(
PhoenixSocket(
endpoint,
socketOptions: new PhoenixSocketOptions(params: params),
socketOptions: PhoenixSocketOptions(params: params),
);

http.Client createHttpClient() => http.Client();
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/connexion_utils_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ PhoenixSocket createPhoenixSocket(
String endpoint,
Map<String, String> params,
) =>
new PhoenixSocket(
PhoenixSocket(
endpoint,
connectionProvider: PhoenixHtmlConnection.provider,
socketOptions: new PhoenixSocketOptions(params: params),
socketOptions: PhoenixSocketOptions(params: params),
);

http.Client createHttpClient() {
Expand Down
8 changes: 4 additions & 4 deletions lib/views/loading_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class LoadingButton extends StatelessWidget {
// }

return LenraButton(
onPressed: !this.loading ? this.onPressed : null,
disabled: this.loading ? true : false,
text: this.text,
rightIcon: /*this.loading ? CircularProgressIndicator() :*/ this.rightIcon,
onPressed: !loading ? onPressed : null,
disabled: loading ? true : false,
text: text,
rightIcon: /*this.loading ? CircularProgressIndicator() :*/ rightIcon,
);
}
}
23 changes: 15 additions & 8 deletions lib/views/simple_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,33 @@ class SimplePage extends StatelessWidget {
child: Text(
title,
style: theme.lenraTextThemeData.headline2,
textAlign: this.textAlign,
textAlign: textAlign,
),
));
}
if (title.isNotEmpty && message.isNotEmpty) children.add(SizedBox(height: theme.baseSize * 2));
if (title.isNotEmpty && message.isNotEmpty) {
children.add(SizedBox(height: theme.baseSize * 2));
}
if (message.isNotEmpty) {
children.add(SizedBox(
width: double.infinity,
child: Text(
message,
style: theme.lenraTextThemeData.disabledBodyText,
textAlign: this.textAlign,
textAlign: textAlign,
),
));
}
if (child != null) {
if (title.isNotEmpty || message.isNotEmpty) children.add(SizedBox(height: theme.baseSize * 4));
if (title.isNotEmpty || message.isNotEmpty) {
children.add(SizedBox(height: theme.baseSize * 4));
}
children.add(child!);
}

var size = MediaQuery.of(context).size;
var padding = min(min(size.height * 0.08, size.width * 0.1), theme.baseSize * 10);
var padding =
min(min(size.height * 0.08, size.width * 0.1), theme.baseSize * 10);
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
Expand All @@ -72,7 +77,7 @@ class SimplePage extends StatelessWidget {
child: Column(
children: _buildBackInk(context, theme)
..add(Center(
child: new Container(
child: Container(
width: 400,
child: Column(
children: children,
Expand All @@ -90,15 +95,17 @@ class SimplePage extends StatelessWidget {
List<Widget> _buildBackInk(BuildContext context, LenraThemeData theme) {
var size = MediaQuery.of(context).size;
var inkSize = 20;
var separation = min(min(size.height * 0.05, size.width * 0.06), theme.baseSize * 6);
var separation =
min(min(size.height * 0.05, size.width * 0.06), theme.baseSize * 6);
if (backInkText == null || backInkText!.isEmpty) {
return [
SizedBox(
height: inkSize + separation,
)
];
}
var linkTheme = theme.lenraTextThemeData.bodyText.copyWith(color: theme.lenraColorThemeData.primaryBackgroundColor);
var linkTheme = theme.lenraTextThemeData.bodyText
.copyWith(color: theme.lenraColorThemeData.primaryBackgroundColor);
return [
Align(
alignment: Alignment.topLeft,
Expand Down
4 changes: 2 additions & 2 deletions lib/views/stateful_wrapper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';

typedef Widget Builder(BuildContext context);
typedef Builder = Widget Function(BuildContext context);

/// Wrapper for stateful functionality to provide onInit calls in stateles widget
/// from https://medium.com/filledstacks/how-to-call-a-function-on-start-in-flutter-stateless-widgets-28d90ab3bf49
Expand All @@ -12,7 +12,7 @@ class StatefulWrapper extends StatefulWidget {
required this.builder,
});
@override
_StatefulWrapperState createState() => _StatefulWrapperState();
State<StatefulWrapper> createState() => _StatefulWrapperState();
}

class _StatefulWrapperState extends State<StatefulWrapper> {
Expand Down
2 changes: 1 addition & 1 deletion test/api/request_models/login_request_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';

import 'package:client_common/api/request_models/loginRequest.dart';
import 'package:client_common/api/request_models/login_request.dart';
import 'package:test/test.dart';

void main() {
Expand Down

0 comments on commit 3bbb069

Please sign in to comment.