import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FirstPage(),
);
}
}
class FirstPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Scaffold(
bottomNavigationBar: BottomAppBar(
color: Colors.red,
child: Row(
children: [
SizedBox(height: 45,)
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Secondpage(),
),
);
},
child: Text('change to next page'),
)
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
),
),
);
}
}
class Secondpage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomAppBar(
color: Colors.red,
child: Row(
children: [
SizedBox(height: 45,)
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () {
final snackBar = SnackBar(
content: Text('Snackbar'),
behavior: SnackBarBehavior.floating,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: Text('Display snackbar'),
),
TextButton(
onPressed: () {
Navigator.pop(context, null);
},
child: Text('Back'),
)
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
),
);
}
}
If you try to use ScaffoldManager to display a SnackBar and you have multiple scaffold you will get multiple snackbar
Code
flutter doctor -v