Skip to content

Feat: ajout de l'action simulateur Mes Aides Réno #590

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

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 10 additions & 5 deletions app/lib/features/action/domain/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ final class ActionSimulator extends Action {
@override
List<Object?> get props => [...super.props, why, questions];

ActionSimulatorId getId() => switch (id) {
'action_simulateur_voiture' => ActionSimulatorId.carSimulator,
_ => throw UnimplementedError(),
};
ActionSimulatorId getId() => actionSimulatorIdFromAPIString(id);

@override
String get instruction => 'Terminez ce simulateur et gagnez';
Expand All @@ -148,8 +145,16 @@ final class ActionSimulator extends Action {
ActionType get type => ActionType.simulator;
}

enum ActionSimulatorId { carSimulator }
enum ActionSimulatorId { carSimulator, mesAidesReno }

// FIXME(erolley): refactor with enum, see velo_etat
String actionSimulatorIdToAPIString(final ActionSimulatorId id) => switch (id) {
ActionSimulatorId.carSimulator => 'action_simulateur_voiture',
ActionSimulatorId.mesAidesReno => 'simu_aides_reno',
};

ActionSimulatorId actionSimulatorIdFromAPIString(final String id) => switch (id) {
'action_simulateur_voiture' => ActionSimulatorId.carSimulator,
'simu_aides_reno' => ActionSimulatorId.mesAidesReno,
_ => throw UnimplementedError('Trying to get an unknown id: $id'),
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:app/features/action/domain/action.dart';
import 'package:app/features/action/presentation/widgets/action_why_section_view.dart';
import 'package:app/features/car_simulator/presentation/widgets/car_simulator_widget.dart';
import 'package:app/features/mes_aides_reno/presentation/mes_aides_reno_widget.dart';
import 'package:flutter/material.dart';

class ActionSimulatorView extends StatelessWidget {
Expand All @@ -14,6 +15,7 @@ class ActionSimulatorView extends StatelessWidget {
if (action.why != null) ActionWhySectionView(why: action.why!),
switch (action.getId()) {
ActionSimulatorId.carSimulator => CarSimulatorWidget(isDone: action.isDone),
ActionSimulatorId.mesAidesReno => MesAidesRenoWidget(isDone: action.isDone),
},
],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class MesAidesRenoWidget extends StatefulWidget {
const MesAidesRenoWidget({super.key, required this.isDone});

final bool isDone;

@override
State<MesAidesRenoWidget> createState() => _MesAidesRenoWidgetState();
}

class _MesAidesRenoWidgetState extends State<MesAidesRenoWidget> {
double _webViewHeight = 700;

@override
Widget build(final BuildContext context) => SizedBox(
height: _webViewHeight,
child: InAppWebView(
initialSettings: InAppWebViewSettings(isInspectable: kDebugMode, iframeAllow: 'clipboard-read; clipboard-write'),
initialUrlRequest: URLRequest(url: WebUri('https://mesaidesreno.beta.gouv.fr')),
onLoadStop: (final controller, final url) async {
await controller.evaluateJavascript(source: _injectEventListeners);
},
onWebViewCreated: (final controller) {
controller.addJavaScriptHandler(
handlerName: 'mesAidesRenoHandler',
callback: (final args) {
final data = args.first as Map<String, dynamic>;

switch (data['kind']) {
case 'mesaidesreno-resize-height':
{
setState(() {
_webViewHeight = double.parse(data['value'].toString()) + 20;
});
break;
}
}
},
);
},
),
);
}

const _injectEventListeners = '''
if (!window.flutterMessageListenerAttached) {
window.flutterMessageListenerAttached = true;

window.addEventListener("message", (event) => {
window.flutter_inappwebview.callHandler("mesAidesRenoHandler", event.data);
}, false);
}
''';
6 changes: 6 additions & 0 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import 'dart:async';

import 'package:app/app/app_setup.dart';
import 'package:app/core/error/infrastructure/error_handler.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Expand All @@ -11,5 +13,9 @@ Future<void> main() async {
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
await ErrorHandler.register();

if (defaultTargetPlatform == TargetPlatform.android) {
await InAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode);
}

runApp(const AppSetup());
}
64 changes: 64 additions & 0 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "9.1.0"
flutter_inappwebview:
dependency: "direct main"
description:
name: flutter_inappwebview
sha256: "80092d13d3e29b6227e25b67973c67c7210bd5e35c4b747ca908e31eb71a46d5"
url: "https://pub.dev"
source: hosted
version: "6.1.5"
flutter_inappwebview_android:
dependency: transitive
description:
name: flutter_inappwebview_android
sha256: "62557c15a5c2db5d195cb3892aab74fcaec266d7b86d59a6f0027abd672cddba"
url: "https://pub.dev"
source: hosted
version: "1.1.3"
flutter_inappwebview_internal_annotations:
dependency: transitive
description:
name: flutter_inappwebview_internal_annotations
sha256: "787171d43f8af67864740b6f04166c13190aa74a1468a1f1f1e9ee5b90c359cd"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
flutter_inappwebview_ios:
dependency: transitive
description:
name: flutter_inappwebview_ios
sha256: "5818cf9b26cf0cbb0f62ff50772217d41ea8d3d9cc00279c45f8aabaa1b4025d"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
flutter_inappwebview_macos:
dependency: transitive
description:
name: flutter_inappwebview_macos
sha256: c1fbb86af1a3738e3541364d7d1866315ffb0468a1a77e34198c9be571287da1
url: "https://pub.dev"
source: hosted
version: "1.1.2"
flutter_inappwebview_platform_interface:
dependency: transitive
description:
name: flutter_inappwebview_platform_interface
sha256: cf5323e194096b6ede7a1ca808c3e0a078e4b33cc3f6338977d75b4024ba2500
url: "https://pub.dev"
source: hosted
version: "1.3.0+1"
flutter_inappwebview_web:
dependency: transitive
description:
name: flutter_inappwebview_web
sha256: "55f89c83b0a0d3b7893306b3bb545ba4770a4df018204917148ebb42dc14a598"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
flutter_inappwebview_windows:
dependency: transitive
description:
name: flutter_inappwebview_windows
sha256: "8b4d3a46078a2cdc636c4a3d10d10f2a16882f6be607962dbfff8874d1642055"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
flutter_inset_shadow:
dependency: "direct main"
description:
Expand Down
3 changes: 2 additions & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: app
description: "J’agis vous accompagne à chaque étape de la transition écologique."
publish_to: 'none'
publish_to: "none"
version: 0.16.23+0

environment:
Expand All @@ -21,6 +21,7 @@ dependencies:
flutter:
sdk: flutter
flutter_bloc: 9.1.0
flutter_inappwebview: ^6.1.5
flutter_inset_shadow: 2.0.3
flutter_localizations:
sdk: flutter
Expand Down
Loading