Skip to content

Commit

Permalink
implement toast layer from root
Browse files Browse the repository at this point in the history
  • Loading branch information
tilucasoli committed Jan 20, 2025
1 parent 10083ca commit 89ffe9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 8 additions & 2 deletions packages/remix/lib/src/components/toast/toast_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ class ToastLayerState extends State<ToastLayer> implements ToastActions {
}
}

void showToast({required BuildContext context, required ToastEntry entry}) {
final toastState = context.findAncestorStateOfType<ToastLayerState>();
void showToast({
required BuildContext context,
bool useRootNavigator = true,
required ToastEntry entry,
}) {
final toastState = useRootNavigator
? context.findRootAncestorStateOfType<ToastLayerState>()
: context.findAncestorStateOfType<ToastLayerState>();

if (toastState == null) {
throw FlutterError.fromParts([
Expand Down
17 changes: 10 additions & 7 deletions packages/remix/lib/src/core/remix_app.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart' as m;
import 'package:flutter/widgets.dart';

import '../components/toast/toast.dart';
import 'theme/remix_theme.dart';

//ignore: avoid-unnecessary-stateful-widgets
Expand Down Expand Up @@ -123,13 +124,15 @@ class _RemixAppState extends State<RemixApp> {
return RemixTheme(
theme: widget.theme,
darkTheme: widget.darkTheme ?? widget.theme,
child: widget.builder != null
? Builder(
builder: (BuildContext context) {
return widget.builder!(context, child);
},
)
: (child ?? const SizedBox.shrink()),
child: ToastLayer(
child: widget.builder != null
? Builder(
builder: (BuildContext context) {
return widget.builder!(context, child);
},
)
: (child ?? const SizedBox.shrink()),
),
);
}

Expand Down

0 comments on commit 89ffe9c

Please sign in to comment.