I want to add a Snack bar that tells a user to scroll up when images added to the body is more than 2..the problem is I can't put the snack bar in a scaffold because the add image button is just a reference in the scaffold widget. I'm new to asking questions so I might not have asked correctly.
class App extends StatefulWidget {
createState() {
return AppState();
}
}
class AppState extends State<App> {
int counter = 0;
List<ImageModel> images = [];
void fetchImage() async {
counter++;
while (counter > 2) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Scroll Up'),
duration: Duration(seconds: 2),
));
}
var response =
await get('http://jsonplaceholder.typicode.com/photos/$counter');
var imageModel = ImageModel.fromJson(json.decode(response.body));
setState(
() {
images.add(imageModel);
},
);
}
Widget build(context) {
return MaterialApp(
home: Scaffold(
body: ImageList(images),
backgroundColor: Colors.blueGrey.shade200,
bottomNavigationBar: BottomAppBar(
shape: const CircularNotchedRectangle(),
child: Container(
height: 50.0,
//color: Colors.blue,
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.blueGrey,
child: Icon(Icons.add),
onPressed: fetchImage,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
appBar: AppBar(
title: Text("Let's see images!"),
),
),
);
}
}