Skip to content
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

feat: implement toast layer from root #549

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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
Loading