Skip to content

Instantly share code, notes, and snippets.

@filiph
Created August 8, 2020 01:45
Show Gist options
  • Save filiph/d0c001b702129c59c9f0b8e5faf028bd to your computer and use it in GitHub Desktop.
Save filiph/d0c001b702129c59c9f0b8e5faf028bd to your computer and use it in GitHub Desktop.
SnackBar regression
import 'package:flutter/material.dart';
void main() => runApp(SnackBarDemo());
class SnackBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SnackBar Demo',
home: Scaffold(
appBar: AppBar(
title: Text('SnackBar Demo'),
),
body: SnackBarPage(),
bottomSheet: Container(
color: Colors.yellow,
child: SizedBox(
height: 200,
child: Text('Bottom sheet'),
),
),
),
);
}
}
class SnackBarPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
onPressed: () {
final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
content: Text('Yay! A SnackBar!'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
// Some code to undo the change.
},
),
);
// Find the Scaffold in the widget tree and use
// it to show a SnackBar.
Scaffold.of(context).showSnackBar(snackBar);
},
child: Text('Show SnackBar'),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment