xxxxxxxxxx
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Snackbar Example'),
),
body: MyWidget(),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
child: Text('Show Snackbar'),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('This is a snackbar'),
duration: Duration(seconds: 3), // Adjust the duration as needed
behavior: SnackBarBehavior.floating,
),
);
},
),
);
}
}
xxxxxxxxxx
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Your Text"),
duration: Duration(milliseconds: 300),
));
xxxxxxxxxx
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
content: Text('Snackbar message'),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height - 100,
right: 20,
left: 20),
));
xxxxxxxxxx
SnackBar(
behavior: SnackBarBehavior.floating,
margin: EdgeInsets.only(bottom: 100.0),
content: Text("Hello World!"),
);
xxxxxxxxxx
final snackBar = SnackBar(
content: const Text('Yay! A SnackBar!'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {},
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
xxxxxxxxxx
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(milliseconds: 5000),
content: const Text('Awesome Snackbar!'),
),
);
xxxxxxxxxx
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Select car Type first'),
));
xxxxxxxxxx
final snackBar = SnackBar(
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);
xxxxxxxxxx
final snackBar = SnackBar(content: Text('Yay! A SnackBar!'));
// Find the ScaffoldMessenger in the widget tree
// and use it to show a SnackBar.
ScaffoldMessenger.of(context).showSnackBar(snackBar);
xxxxxxxxxx
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
void showInSnackBar(String value) {
_scaffoldKey.currentState.showSnackBar(new SnackBar(content: new Text(value)));
}