Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Migrate SnackBar methods to ScaffoldMessenger #343

Merged
merged 6 commits into from
Oct 12, 2020
Merged
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
147 changes: 49 additions & 98 deletions lib/codeviewer/code_segments.dart

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions lib/demos/material/dialog_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ enum DialogDemoType {
class DialogDemo extends StatelessWidget {
DialogDemo({Key key, @required this.type}) : super(key: key);

final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
final DialogDemoType type;

String _title(BuildContext context) {
Expand Down Expand Up @@ -49,8 +48,8 @@ class DialogDemo extends StatelessWidget {
);
// The value passed to Navigator.pop() or null.
if (value != null && value is String) {
_scaffoldKey.currentState.hideCurrentSnackBar();
_scaffoldKey.currentState.showSnackBar(SnackBar(
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content:
Text(GalleryLocalizations.of(context).dialogSelectedOption(value)),
));
Expand Down Expand Up @@ -132,7 +131,6 @@ class DialogDemo extends StatelessWidget {
onGenerateRoute: (settings) {
return _NoAnimationMaterialPageRoute<void>(
builder: (context) => Scaffold(
key: _scaffoldKey,
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text(_title(context)),
Expand Down
4 changes: 2 additions & 2 deletions lib/demos/material/menu_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class _MenuDemoState extends State<MenuDemo> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

void showInSnackBar(String value) {
_scaffoldKey.currentState.hideCurrentSnackBar();
_scaffoldKey.currentState.showSnackBar(SnackBar(
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(value),
));
}
Expand Down
53 changes: 22 additions & 31 deletions lib/demos/material/snackbar_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,28 @@ class SnackbarsDemo extends StatelessWidget {
automaticallyImplyLeading: false,
title: Text(GalleryLocalizations.of(context).demoSnackbarsTitle),
),
body: Builder(
// Create an inner BuildContext so that the snackBar onPressed methods
// can refer to the Scaffold with Scaffold.of().
builder: (context) {
return Center(
child: RaisedButton(
child: Text(
GalleryLocalizations.of(context).demoSnackbarsButtonLabel),
onPressed: () {
Scaffold.of(context).hideCurrentSnackBar();
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
GalleryLocalizations.of(context).demoSnackbarsText,
),
action: SnackBarAction(
label: GalleryLocalizations.of(context)
.demoSnackbarsActionButtonLabel,
onPressed: () {
Scaffold.of(context).hideCurrentSnackBar();
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
GalleryLocalizations.of(context).demoSnackbarsAction,
),
));
},
),
));
},
),
);
},
body: Center(
child: RaisedButton(
child:
Text(GalleryLocalizations.of(context).demoSnackbarsButtonLabel),
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(GalleryLocalizations.of(context).demoSnackbarsText),
action: SnackBarAction(
label: GalleryLocalizations.of(context)
.demoSnackbarsActionButtonLabel,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
GalleryLocalizations.of(context).demoSnackbarsAction,
)));
},
),
));
},
),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/demos/material/text_field_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
PersonData person = PersonData();

void showInSnackBar(String value) {
_scaffoldKey.currentState.hideCurrentSnackBar();
_scaffoldKey.currentState.showSnackBar(SnackBar(
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(value),
));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ class CodeDisplayPage extends StatelessWidget {
final _plainTextCode = _richTextCode.toPlainText();

void _showSnackBarOnCopySuccess(dynamic result) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
GalleryLocalizations.of(context)
Expand All @@ -744,7 +744,7 @@ class CodeDisplayPage extends StatelessWidget {
}

void _showSnackBarOnCopyFailure(Object exception) {
Scaffold.of(context).showSnackBar(
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
GalleryLocalizations.of(context)
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0-nullsafety.4"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -581,7 +581,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0-nullsafety.2"
stream_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -744,5 +744,5 @@ packages:
source: hosted
version: "2.2.1"
sdks:
dart: ">=2.10.0-110 <2.11.0"
dart: ">=2.10.0-110 <=2.11.0-207.0.dev"
flutter: ">=1.17.0 <2.0.0"