Skip to content

Commit

Permalink
Make non-visual controls working with routing
Browse files Browse the repository at this point in the history
Fix #1324, fix #1236
  • Loading branch information
FeodorFitsner committed Apr 24, 2023
1 parent 4b4dc11 commit a4f6528
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 38 deletions.
6 changes: 4 additions & 2 deletions package/lib/src/controls/alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class AlertDialogControl extends StatefulWidget {
final Control control;
final List<Control> children;
final bool parentDisabled;
final Widget? nextChild;

const AlertDialogControl(
{Key? key,
this.parent,
required this.control,
required this.children,
required this.parentDisabled})
required this.parentDisabled,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -125,7 +127,7 @@ class _AlertDialogControlState extends State<AlertDialogControl> {

_open = open;

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
});
}
}
22 changes: 19 additions & 3 deletions package/lib/src/controls/audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_redux/flutter_redux.dart';

import '../actions.dart';
import '../flet_app_services.dart';
import '../models/app_state.dart';
import '../models/control.dart';
import '../models/page_args_model.dart';
import '../protocol/update_control_props_payload.dart';
import '../utils/images.dart';
import 'error.dart';

class AudioControl extends StatefulWidget {
final Control? parent;
final Control control;
final dynamic dispatch;
final Widget? nextChild;

const AudioControl({Key? key, required this.parent, required this.control})
const AudioControl(
{Key? key,
required this.parent,
required this.control,
required this.dispatch,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -193,7 +202,14 @@ class _AudioControlState extends State<AudioControl> {
var method = widget.control.attrString("method");
if (method != null && method != _method) {
_method = method;
debugPrint("Audio JSON value: $_method");
debugPrint("Audio JSON method: $method, $_method");

List<Map<String, String>> props = [
{"i": widget.control.id, "method": ""}
];
widget.dispatch(UpdateControlPropsAction(
UpdateControlPropsPayload(props: props)));
server.updateControlProps(props: props);

var mj = json.decode(method);
var i = mj["i"] as int;
Expand Down Expand Up @@ -245,7 +261,7 @@ class _AudioControlState extends State<AudioControl> {
}
}();

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
});
}
}
6 changes: 4 additions & 2 deletions package/lib/src/controls/banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class BannerControl extends StatefulWidget {
final Control control;
final List<Control> children;
final bool parentDisabled;
final Widget? nextChild;

const BannerControl(
{Key? key,
this.parent,
required this.control,
required this.children,
required this.parentDisabled})
required this.parentDisabled,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -95,7 +97,7 @@ class _BannerControlState extends State<BannerControl> {

_open = open;

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
});
}
}
6 changes: 4 additions & 2 deletions package/lib/src/controls/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ class BottomSheetControl extends StatefulWidget {
final List<Control> children;
final bool parentDisabled;
final dynamic dispatch;
final Widget? nextChild;

const BottomSheetControl(
{Key? key,
this.parent,
required this.control,
required this.children,
required this.parentDisabled,
required this.dispatch})
required this.dispatch,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -90,6 +92,6 @@ class _BottomSheetControlState extends State<BottomSheetControl> {
});
}

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
}
}
8 changes: 6 additions & 2 deletions package/lib/src/controls/clipboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import '../protocol/update_control_props_payload.dart';
class ClipboardControl extends StatefulWidget {
final Control? parent;
final Control control;
final Widget? nextChild;

const ClipboardControl(
{Key? key, required this.parent, required this.control})
{Key? key,
required this.parent,
required this.control,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -74,6 +78,6 @@ class _ClipboardControlState extends State<ClipboardControl> {
}
}();

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
}
}
48 changes: 33 additions & 15 deletions package/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ import 'transparent_pointer.dart';
import 'vertical_divider.dart';
import 'window_drag_area.dart';

Widget createControl(Control? parent, String id, bool parentDisabled) {
Widget createControl(Control? parent, String id, bool parentDisabled,
{Widget? nextChild}) {
//debugPrint("createControl(): $id");
return StoreConnector<AppState, ControlViewModel>(
key: ValueKey<String>(id),
Expand Down Expand Up @@ -99,25 +100,39 @@ Widget createControl(Control? parent, String id, bool parentDisabled) {
return IconControl(parent: parent, control: controlView.control);
case "filepicker":
return FilePickerControl(
parent: parent, control: controlView.control);
parent: parent,
control: controlView.control,
nextChild: nextChild,
);
case "markdown":
return MarkdownControl(parent: parent, control: controlView.control);
case "fletapp":
return FletAppControl(parent: parent, control: controlView.control);
case "image":
return ImageControl(parent: parent, control: controlView.control);
case "audio":
return AudioControl(parent: parent, control: controlView.control);
return AudioControl(
parent: parent,
control: controlView.control,
dispatch: controlView.dispatch,
nextChild: nextChild);
case "divider":
return DividerControl(parent: parent, control: controlView.control);
case "clipboard":
return ClipboardControl(parent: parent, control: controlView.control);
return ClipboardControl(
parent: parent,
control: controlView.control,
nextChild: nextChild);
case "hapticfeedback":
return HapticFeedbackControl(
parent: parent, control: controlView.control);
parent: parent,
control: controlView.control,
nextChild: nextChild);
case "shakedetector":
return ShakeDetectorControl(
parent: parent, control: controlView.control);
parent: parent,
control: controlView.control,
nextChild: nextChild);
case "verticaldivider":
return VerticalDividerControl(
parent: parent, control: controlView.control);
Expand Down Expand Up @@ -319,27 +334,30 @@ Widget createControl(Control? parent, String id, bool parentDisabled) {
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled);
parentDisabled: parentDisabled,
nextChild: nextChild);
case "alertdialog":
return AlertDialogControl(
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled);
parentDisabled: parentDisabled,
nextChild: nextChild);
case "bottomsheet":
return BottomSheetControl(
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
dispatch: controlView.dispatch,
);
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
dispatch: controlView.dispatch,
nextChild: nextChild);
case "banner":
return BannerControl(
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled);
parentDisabled: parentDisabled,
nextChild: nextChild);
case "tabs":
return TabsControl(
parent: parent,
Expand Down
8 changes: 6 additions & 2 deletions package/lib/src/controls/file_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import '../utils/strings.dart';
class FilePickerControl extends StatefulWidget {
final Control? parent;
final Control control;
final Widget? nextChild;

const FilePickerControl(
{Key? key, required this.parent, required this.control})
{Key? key,
required this.parent,
required this.control,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -161,7 +165,7 @@ class _FilePickerControlState extends State<FilePickerControl> {
uploadFiles(upload, FletAppServices.of(context).server, pageUri!);
}

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
});
}

Expand Down
8 changes: 6 additions & 2 deletions package/lib/src/controls/haptic_feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import '../protocol/update_control_props_payload.dart';
class HapticFeedbackControl extends StatefulWidget {
final Control? parent;
final Control control;
final Widget? nextChild;

const HapticFeedbackControl(
{Key? key, required this.parent, required this.control})
{Key? key,
required this.parent,
required this.control,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -60,6 +64,6 @@ class _HapticFeedbackControlState extends State<HapticFeedbackControl> {
}
}();

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
}
}
19 changes: 15 additions & 4 deletions package/lib/src/controls/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ class _PageControlState extends State<PageControl> {
List<Widget> overlayWidgets = [];

if (viewId == routesView.viewIds.last) {
overlayWidgets.addAll(routesView.offstageControls.map((c) =>
createControl(
overlayWidgets.addAll(routesView.offstageControls
.where((c) => !c.isNonVisual)
.map((c) => createControl(
routesView.page, c.id, routesView.page.isDisabled)));
overlayWidgets.add(const PageMedia());
}
Expand All @@ -504,7 +505,7 @@ class _PageControlState extends State<PageControl> {
_prevViewsIds = viewIds;
}

return Navigator(
Widget nextChild = Navigator(
key: navigatorKey,
pages: pages,
onPopPage: (route, dynamic result) {
Expand All @@ -515,6 +516,16 @@ class _PageControlState extends State<PageControl> {
((route.settings as Page).key as ValueKey).value);
return false;
});

// wrap navigator into non-visual offstage controls
for (var c
in routesView.offstageControls.where((c) => c.isNonVisual)) {
nextChild = createControl(
routesView.page, c.id, routesView.page.isDisabled,
nextChild: nextChild);
}

return nextChild;
});
}

Expand Down Expand Up @@ -605,7 +616,7 @@ class _PageControlState extends State<PageControl> {
return false;
},
builder: (context, childrenViews) {
debugPrint("Route view StoreConnector build");
debugPrint("Route view StoreConnector build: $viewId");

var appBarView =
appBar != null ? childrenViews.controlViews.last : null;
Expand Down
8 changes: 6 additions & 2 deletions package/lib/src/controls/shake_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import '../models/control.dart';
class ShakeDetectorControl extends StatefulWidget {
final Control? parent;
final Control control;
final Widget? nextChild;

const ShakeDetectorControl(
{Key? key, required this.parent, required this.control})
{Key? key,
required this.parent,
required this.control,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -64,6 +68,6 @@ class _ShakeDetectorControlState extends State<ShakeDetectorControl> {
);
}

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
}
}
6 changes: 4 additions & 2 deletions package/lib/src/controls/snack_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class SnackBarControl extends StatefulWidget {
final Control control;
final List<Control> children;
final bool parentDisabled;
final Widget? nextChild;

const SnackBarControl(
{Key? key,
this.parent,
required this.control,
required this.children,
required this.parentDisabled})
required this.parentDisabled,
required this.nextChild})
: super(key: key);

@override
Expand Down Expand Up @@ -107,7 +109,7 @@ class _SnackBarControlState extends State<SnackBarControl> {

_open = open;

return const SizedBox.shrink();
return widget.nextChild ?? const SizedBox.shrink();
});
}
}
Loading

0 comments on commit a4f6528

Please sign in to comment.