Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into prod/festapp
Browse files Browse the repository at this point in the history
  • Loading branch information
miakh committed Aug 8, 2024
2 parents f27f8cd + d4ebf35 commit 0ce2d32
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/RouterService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class RouterService{
GoRoute(
path: HtmlEditorPage.ROUTE,
builder: (context, state) =>
HtmlEditorPage(content: state.extra as String?),
HtmlEditorPage(content: state.extra as Map<String, dynamic>),
),
GoRoute(
path: AdministrationPage.ROUTE,
Expand Down
25 changes: 13 additions & 12 deletions lib/pages/AdministrationPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,20 @@ class _AdministrationPageState extends State<AdministrationPage> with SingleTick
{
textToEdit = oldText;
}
if(textToEdit == null)
{
Future<String?> Function() load = () async {
var id = rendererContext.row.cells[Tb.information.id]!.value;

if(id!=null)
{
var infoDescription = await DataService.getInfosDescription([id]);
if(infoDescription.isNotEmpty){
textToEdit = infoDescription[0].description;
return infoDescription[0].description;
}
}
}
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: textToEdit).then((value) async {
return null;
};
Map<String, dynamic> param = {HtmlEditorPage.parContent: textToEdit, HtmlEditorPage.parLoad: load};
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: param).then((value) async {
if(value != null)
{
var newText = value as String;
Expand Down Expand Up @@ -346,17 +347,17 @@ class _AdministrationPageState extends State<AdministrationPage> with SingleTick
{
textToEdit = oldText;
}
if(textToEdit == null)
{
Future<String?> Function() load = () async {
var eventId = rendererContext.row.cells[Tb.events.id]!.value;

if(eventId!=null)
{
var fullEvent = await DataService.getEvent(eventId);
textToEdit = fullEvent.description;
return fullEvent.description;
}
}
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: textToEdit).then((value) async {
return null;
};
Map<String, dynamic> param = {HtmlEditorPage.parContent: textToEdit, HtmlEditorPage.parLoad: load};
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: param).then((value) async {
if(value != null)
{
var newText = value as String;
Expand Down Expand Up @@ -613,7 +614,7 @@ class _AdministrationPageState extends State<AdministrationPage> with SingleTick
return ElevatedButton(
onPressed: () async{
var oldText = rendererContext.row.cells[Tb.user_group_info.description]!.value as String?;
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: oldText).then((value) async {
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: {HtmlEditorPage.parContent: oldText}).then((value) async {
if(value != null)
{
var newText = value as String;
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/EventPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ class _EventPageState extends State<EventPage> {
RouterService.navigateOccasion(
context,
HtmlEditorPage.ROUTE,
extra:
_event!.description)
extra: {HtmlEditorPage.parContent:
_event!.description})
.then((value) async {
if (value != null) {
var changed = value as String;
Expand Down
83 changes: 66 additions & 17 deletions lib/pages/HtmlEditorPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,66 @@ import 'package:fstapp/dataServices/DataExtensions.dart';
import 'package:fstapp/styles/Styles.dart';
import 'package:fstapp/widgets/ButtonsHelper.dart';
import 'package:fstapp/widgets/HtmlEditorWidget.dart';
import 'package:go_router/go_router.dart';
import 'package:quill_html_editor/quill_html_editor.dart';
import 'package:flutter/material.dart';

class HtmlEditorPage extends StatefulWidget {
static const String parContent = "content";
static const String parLoad = "load";
static const ROUTE = "htmlEditor";
String? content;
Map<String, dynamic>? content;
HtmlEditorPage({this.content, super.key});

@override
_HtmlEditorPageState createState() => _HtmlEditorPageState();
}

class _HtmlEditorPageState extends State<HtmlEditorPage> {
late String _html;
final String _html = "";
String? _originalHtml;
bool _isTextSet = false;
bool _isContentLoading = false;

Map<String, dynamic>? parameters;
late QuillEditorController controller;

@override
void initState() {
super.initState();
_html = widget.content ?? "";
if (widget.content != null) {
_originalHtml = widget.content?[HtmlEditorPage.parContent];
}


controller = QuillEditorController();
var firstLoad = (t) async {
if(_isTextSet){return;}
await setHtmlText(_originalHtml ?? _html);
_isTextSet = true;
};
controller.onTextChanged(firstLoad);
if (_originalHtml == null) {
_loadHtmlContent();
}
}

Future<void> _loadHtmlContent() async {
setState(() {
_isContentLoading = true;
//avoid double setting of text
_isTextSet = true;
});
try {
_originalHtml = await widget.content?[HtmlEditorPage.parLoad]();
if (_originalHtml != null) {
await setHtmlText(_originalHtml!);
}
} catch (e) {
// Handle error
}
setState(() {
_isContentLoading = false;
});
}

@override
Expand All @@ -40,16 +78,27 @@ class _HtmlEditorPageState extends State<HtmlEditorPage> {
child: Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomInset: true,
body: Align(
alignment: Alignment.topCenter,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: appMaxWidth),
child: HtmlEditorWidget(
initialContent: _html,
controller: controller,
onTextChanged: (text) => debugPrint('listening to $text'),
body: Stack(
children: [
Align(
alignment: Alignment.topCenter,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: appMaxWidth),
child: HtmlEditorWidget(
initialContent: _html,
controller: controller,
onTextChanged: (text) => debugPrint('listening to $text'),
),
),
),
),
if (_isContentLoading)
Container(
color: Colors.black54,
child: Center(
child: CircularProgressIndicator(),
),
),
],
),
bottomNavigationBar: Container(
width: double.maxFinite,
Expand All @@ -59,8 +108,8 @@ class _HtmlEditorPageState extends State<HtmlEditorPage> {
children: [
ButtonsHelper.bottomBarButton(
text: "Reset".tr(),
onPressed: () {
setHtmlText(_html);
onPressed: () async {
await setHtmlText(_originalHtml ?? _html);
},
),
ButtonsHelper.bottomBarButton(
Expand Down Expand Up @@ -88,7 +137,7 @@ class _HtmlEditorPageState extends State<HtmlEditorPage> {
RouterService.goBack(context);
}

void setHtmlText(String text) async {
Future<void> setHtmlText(String text) async {
await controller.setText(text);
}
}
}
2 changes: 1 addition & 1 deletion lib/pages/InfoPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _InfoPageState extends State<InfoPage> {
onPressed: () async {
var result = await RouterService.navigateOccasion(
context, HtmlEditorPage.ROUTE,
extra: item.description);
extra: {HtmlEditorPage.parContent: item.description});
if (result != null) {
setState(() {
item.description = result as String;
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/NewsPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class _NewsPageState extends State<NewsPage> {
if (choice == ContextMenuChoice.delete) {
await DataService.deleteNewsMessage(message);
} else {
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: message.message).then((value) async {
RouterService.navigateOccasion(context, HtmlEditorPage.ROUTE, extra: {HtmlEditorPage.parContent: message.message}).then((value) async {
if (value != null) {
var newMessage = value as String;
message.message = newMessage;
Expand Down

0 comments on commit 0ce2d32

Please sign in to comment.