-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/lib/features/mes_aides_reno/bloc/mes_aides_reno_bloc.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
app/lib/features/mes_aides_reno/bloc/mes_aides_reno_event.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
app/lib/features/mes_aides_reno/bloc/mes_aides_reno_state.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
105 changes: 105 additions & 0 deletions
105
app/lib/features/mes_aides_reno/presentation/mes_aides_reno_widget.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
'''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.