[go: nahoru, domu]

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

ScaffoldMessenger #64101

Merged
merged 11 commits into from
Sep 3, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
++
  • Loading branch information
Piinks committed Aug 26, 2020
commit 20d8afdc6138322132d4cf314dc31e4e8f768c1c
126 changes: 87 additions & 39 deletions packages/flutter/lib/src/material/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,10 @@ class ScaffoldMessenger extends StatefulWidget {
/// If there is no [ScaffoldMessenger] in scope, then this will throw an
/// exception. To return null if there is no [ScaffoldMessenger], then pass
/// `nullOk: true`.
Piinks marked this conversation as resolved.
Show resolved Hide resolved
static ScaffoldMessengerState of(BuildContext context, { bool nullOk = false }) {
assert(nullOk != null);
static ScaffoldMessengerState of(BuildContext context) {
assert(context != null);
final _ScaffoldMessengerScope scope = context.dependOnInheritedWidgetOfExactType<_ScaffoldMessengerScope>();
if (nullOk || scope != null)
return scope?._scaffoldMessengerState;
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'ScaffoldMessenger.of() called with a context that does not contain a '
'ScaffoldMessenger.'
),
ErrorDescription(
'No ScaffoldMessenger ancestor could be found starting from the context '
'that was passed to ScaffoldMessenger.of().'
),
ErrorHint(
'A ScaffoldMessenger is always available within the contex of a '
'MaterialApp, or you can place your own above this context in order to '
'create your own scope for the ScaffoldMessenger to present SnackBars.'
),
context.describeElement('The context used was')
]);
return scope?._scaffoldMessengerState;
}

@override
Expand Down Expand Up @@ -222,7 +204,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
_scaffolds.remove(scaffold);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to verify that scaffolds only get unregistered once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we assert(_scaffolds.remove(scaffold)) here?

}

/// Distributes a [SnackBar] across all registered [Scaffolds].
/// Distributes a [SnackBar] across all registered [Scaffold]s.
Piinks marked this conversation as resolved.
Show resolved Hide resolved
///
/// A scaffold can show at most one snack bar at a time. If this function is
/// called while another snack bar is already visible, the given snack bar
Expand Down Expand Up @@ -318,7 +300,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
}

/// Removes the current [SnackBar] (if any) immediately from registered
/// [Scaffolds].
/// [Scaffold]s.
///
/// The removed snack bar does not run its normal exit animation. If there are
/// any queued snack bars, they begin their entrance animation immediately.
Expand Down Expand Up @@ -2056,10 +2038,10 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
/// To control how long a [SnackBar] remains visible, use [SnackBar.duration].
///
/// To remove the [SnackBar] with an exit animation, use
/// [ScaffoldMessenger.hideCurrentSnackBar] or call
/// [ScaffoldMessengerState.hideCurrentSnackBar] or call
/// [ScaffoldFeatureController.close] on the returned [ScaffoldFeatureController].
/// To remove a [SnackBar] suddenly (without an animation), use
/// [ScaffoldMessenger.removeCurrentSnackBar].
/// [ScaffoldMessengerState.removeCurrentSnackBar].
///
/// See [ScaffoldMessenger.of] for information about how to obtain the
/// [ScaffoldMessengerState].
Expand All @@ -2083,37 +2065,103 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
/// }
/// ```
/// {@end-tool}
@Deprecated(
'Use ScaffoldMessenger.showSnackBar instead. '
'This feature was deprecated after 1.21.0-2.0.pre.70.'
)
// TODO(Piinks): Deprecate after customers are migrated
// @Deprecated(
// 'Use ScaffoldMessenger.showSnackBar instead. '
// 'This feature was deprecated after TBD'
// )
Piinks marked this conversation as resolved.
Show resolved Hide resolved
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> showSnackBar(SnackBar snackbar) {
assert(_scaffoldMessenger != null);
assert(() {
if(_scaffoldMessenger == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'ScaffoldState.showSnackBar called with a context that does '
'not contain a ScaffoldMessenger.'
),
ErrorDescription(
'SnackBars are managed by the ScaffoldMessenger instead of the Scaffold.'
),
ErrorHint(
'Try calling ScaffoldMessengerState.showSnackBar instead.'
),
ErrorHint(
'A ScaffoldMessenger is always available within the contex of a '
'MaterialApp, or you can place your own above this context in order to '
'create your own scope for the ScaffoldMessenger to present SnackBars.'
),
]);
}
return true;
}());
return _scaffoldMessenger.showSnackBar(snackbar);
}

/// Removes the current [SnackBar] (if any) immediately.
///
/// The removed snack bar does not run its normal exit animation. If there are
/// any queued snack bars, they begin their entrance animation immediately.
@Deprecated(
'Use ScaffoldMessenger.removeCurrentSnackBar instead. '
'This feature was deprecated after 1.21.0-2.0.pre.70.'
)
// TODO(Piinks): Deprecate after customers are migrated
// @Deprecated(
// 'Use ScaffoldMessenger.removeCurrentSnackBar instead. '
// 'This feature was deprecated after TBD'
// )
Piinks marked this conversation as resolved.
Show resolved Hide resolved
void removeCurrentSnackBar({ SnackBarClosedReason reason = SnackBarClosedReason.remove }) {
assert(_scaffoldMessenger != null);
assert(() {
if(_scaffoldMessenger == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'ScaffoldState.removeCurrentSnackBar called with a context that does '
'not contain a ScaffoldMessenger.'
),
ErrorDescription(
'SnackBars are managed by the ScaffoldMessenger instead of the Scaffold.'
),
ErrorHint(
'Try calling ScaffoldMessengerState.removeCurrentSnackBar instead.'
),
ErrorHint(
'A ScaffoldMessenger is always available within the contex of a '
'MaterialApp, or you can place your own above this context in order to '
'create your own scope for the ScaffoldMessenger to present SnackBars.'
),
]);
}
return true;
}());
_scaffoldMessenger.removeCurrentSnackBar(reason: reason);
}

/// Removes the current [SnackBar] by running its normal exit animation.
///
/// The closed completer is called after the animation is complete.
@Deprecated(
'Use ScaffoldMessenger.hideCurrentSnackBar instead. '
'This feature was deprecated after 1.21.0-2.0.pre.70.'
)
// TODO(Piinks): Deprecate after customers are migrated.
// @Deprecated(
// 'Use ScaffoldMessenger.hideCurrentSnackBar instead. '
// 'This feature was deprecated after TBD'
// )
Piinks marked this conversation as resolved.
Show resolved Hide resolved
void hideCurrentSnackBar({ SnackBarClosedReason reason = SnackBarClosedReason.hide }) {
assert(_scaffoldMessenger != null);
assert(() {
if(_scaffoldMessenger == null) {
Piinks marked this conversation as resolved.
Show resolved Hide resolved
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'ScaffoldState.hideCurrentSnackBar called with a context that does '
'not contain a ScaffoldMessenger.'
),
ErrorDescription(
'SnackBars are managed by the ScaffoldMessenger instead of the Scaffold.'
),
ErrorHint(
'Try calling ScaffoldMessengerState.hideCurrentSnackBar instead.'
),
ErrorHint(
'A ScaffoldMessenger is always available within the contex of a '
'MaterialApp, or you can place your own above this context in order to '
'create your own scope for the ScaffoldMessenger to present SnackBars.'
),
]);
}
return true;
}());
_scaffoldMessenger.hideCurrentSnackBar(reason: reason);
}

Expand Down