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 2 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'),
};
62 changes: 33 additions & 29 deletions app/lib/features/action/presentation/pages/action_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,38 @@ class _Success extends StatelessWidget {
final Action action;

@override
Widget build(final context) => ListView(
children: [
const SizedBox(height: DsfrSpacings.s3w),
Padding(
padding: const EdgeInsets.symmetric(horizontal: DsfrSpacings.s2w),
child: ActionTitleWithSubTitleView(title: action.title, subTitle: action.subTitle, type: action.type),
),
const SizedBox(height: DsfrSpacings.s3w),
DecoratedBox(
decoration: const BoxDecoration(color: Colors.white, boxShadow: actionOmbre),
child: Column(
spacing: DsfrSpacings.s3w,
children: [
switch (action) {
ActionClassic() => ActionClassicView(action: action as ActionClassic),
ActionSimulator() => ActionSimulatorView(action: action as ActionSimulator),
ActionQuiz() => ActionQuizView(action: action as ActionQuiz),
},
if (action.aidSummaries.isNotEmpty) ActionAidsView(aidSummaries: action.aidSummaries),
],
Widget build(final context) {
print('========== [DEBUG] ============\n\naction: $action');

return ListView(
children: [
const SizedBox(height: DsfrSpacings.s3w),
Padding(
padding: const EdgeInsets.symmetric(horizontal: DsfrSpacings.s2w),
child: ActionTitleWithSubTitleView(title: action.title, subTitle: action.subTitle, type: action.type),
),
),
const SizedBox(height: DsfrSpacings.s3w),
Padding(
padding: const EdgeInsets.symmetric(horizontal: DsfrSpacings.s2w),
child: ActionScoreInstructionView(action: action),
),
const SafeArea(child: SizedBox(height: DsfrSpacings.s3w)),
],
);
const SizedBox(height: DsfrSpacings.s3w),
DecoratedBox(
decoration: const BoxDecoration(color: Colors.white, boxShadow: actionOmbre),
child: Column(
spacing: DsfrSpacings.s3w,
children: [
switch (action) {
ActionClassic() => ActionClassicView(action: action as ActionClassic),
ActionSimulator() => ActionSimulatorView(action: action as ActionSimulator),
ActionQuiz() => ActionQuizView(action: action as ActionQuiz),
},
if (action.aidSummaries.isNotEmpty) ActionAidsView(aidSummaries: action.aidSummaries),
],
),
),
const SizedBox(height: DsfrSpacings.s3w),
Padding(
padding: const EdgeInsets.symmetric(horizontal: DsfrSpacings.s2w),
child: ActionScoreInstructionView(action: action),
),
const SafeArea(child: SizedBox(height: DsfrSpacings.s3w)),
],
);
}
}
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
11 changes: 11 additions & 0 deletions app/lib/features/mes_aides_reno/bloc/mes_aides_reno_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:app/features/mes_aides_reno/bloc/mes_aides_reno_event.dart';
import 'package:app/features/mes_aides_reno/bloc/mes_aides_reno_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class MesAidesRenoBloc extends Bloc<MesAidesRenoEvent, MesAidesRenoState> {
MesAidesRenoBloc() : super(const MesAidesRenoInit()) {
on<MesAidesRenoMarkAsDone>((final event, final emit) {
emit(const MesAidesRenoActionDone());
});
}
}
15 changes: 15 additions & 0 deletions app/lib/features/mes_aides_reno/bloc/mes_aides_reno_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

@immutable
sealed class MesAidesRenoEvent extends Equatable {
const MesAidesRenoEvent();

@override
List<Object> get props => [];
}

@immutable
final class MesAidesRenoMarkAsDone extends MesAidesRenoEvent {
const MesAidesRenoMarkAsDone();
}
21 changes: 21 additions & 0 deletions app/lib/features/mes_aides_reno/bloc/mes_aides_reno_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:app/features/quiz/domain/quiz.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

@immutable
sealed class MesAidesRenoState extends Equatable {
const MesAidesRenoState();

@override
List<Object> get props => [];
}

@immutable
final class MesAidesRenoInit extends MesAidesRenoState {
const MesAidesRenoInit();
}

@immutable
final class MesAidesRenoActionDone extends MesAidesRenoState {
const MesAidesRenoActionDone();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'package:app/features/action/domain/action.dart';
import 'package:app/features/action/presentation/bloc/action_bloc.dart';
import 'package:app/features/action/presentation/bloc/action_event.dart';
import 'package:app/features/actions/domain/action_type.dart';
import 'package:app/features/mes_aides_reno/bloc/mes_aides_reno_bloc.dart';
import 'package:app/features/mes_aides_reno/bloc/mes_aides_reno_event.dart';
import 'package:app/features/mes_aides_reno/bloc/mes_aides_reno_state.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

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

final bool isDone;

@override
Widget build(final BuildContext context) =>
BlocProvider(create: (final context) => MesAidesRenoBloc(), child: _MesAidesRenoWidget(isDone: isDone));
}

class _MesAidesRenoWidget extends StatefulWidget {
const _MesAidesRenoWidget({required this.isDone});

final bool isDone;

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

class _MesAidesRenoWidgetState extends State<_MesAidesRenoWidget> {
_MesAidesRenoWidgetState();

double webViewHeight = 700;

@override
Widget build(final BuildContext context) => BlocListener<MesAidesRenoBloc, MesAidesRenoState>(
listener: (final context, final state) {
if (state is MesAidesRenoActionDone) {
context.read<ActionBloc>().add(
ActionMarkAsDone(id: actionSimulatorIdToAPIString(ActionSimulatorId.mesAidesReno), type: ActionType.simulator),
);
}
},
child: SizedBox(
height: webViewHeight,
child: InAppWebView(
initialUrlRequest: URLRequest(
url: WebUri(
'https://reno-git-fork-emilerolley-master-mesaidesreno.vercel.app/simulation?iframe=true&logement.EPCI="243100518"&logement.commune="31555"&logement.commune.nom="Toulouse"&vous.propriétaire.statut="non+propriétaire"*&logement.surface=10*&logement.période+de+construction="de+2+à+10+ans"*&DPE.actuel=1*&taxe+foncière.commune.éligible.logement=non&logement.commune.denormandie=non',
),
),
initialSettings: InAppWebViewSettings(iframeAllow: 'clipboard-read; clipboard-write', isInspectable: kDebugMode),
onWebViewCreated: (final controller) {
controller.addJavaScriptHandler(
handlerName: 'mesAidesRenoHandler',
callback: (final args) {
try {
final data = args[0] as Map<String, dynamic>;

switch (data['kind']) {
case 'mesaidesreno-resize-height':
{
setState(() {
webViewHeight = double.parse(data['value'].toString()) + 20;
});
break;
}
case 'mesaidesreno-simulation-done':
{
context.read<MesAidesRenoBloc>().add(const MesAidesRenoMarkAsDone());
break;
}
}
} on Exception catch (e) {
throw Exception('Erreur de décodage du message: $e');
}
return null;
},
);
},
onLoadStop: (final controller, final url) async {
await controller.evaluateJavascript(source: _injectEventListeners);
},
// read search params when url changed to get answered questions
onUpdateVisitedHistory: (final controller, final uri, final androidIsReload) async {
print('uri: ${uri?.path}');
print('parameters: ${uri?.queryParametersAll}');
},
onConsoleMessage: (final controller, final consoleMessage) {},
),
),
);
}

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

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

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final widgetsBinding = SentryWidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
await ErrorHandler.register();

if (!kIsWeb && 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