I want to redirect my current flutter page to home page when back button is pressed. When i press back button the home page/activity should start. I have multiple selections in home page and in current page i am displaying eyes if user don't want to select they can press back to go to homepage.
here is code for my current page/activity
import '../DataFetching/face_part.dart';
import 'package:flutter/material.dart';
class EyesFetch extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_DataFetching createState() => _DataFetching();
}
class _DataFetching extends State<MyHomePage>{
Future<List<facial>> list = facial.alleyes();
List<facial> alleyes=new List<facial>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("fetch"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new FutureBuilder<List<facial>>(
future: list, // a previously-obtained Future<String> or null
builder: (BuildContext context, AsyncSnapshot<List<facial>> snapshot) {
List<Widget> children;
if (snapshot.hasData) {
var result=snapshot.data;
for(var item in result)
{
alleyes.add(new facial(criminal_id: item.criminal_id,
part_size: item.part_size,
link: item.link));
}
children = <Widget>[
new Padding(
padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
child: getHomePageBody(context))
];
} else if (snapshot.hasError) {
children = <Widget>[
Icon(
Icons.error_outline,
color: Colors.red,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('Error: ${snapshot.error}'),
)
];
} else {
children = <Widget>[
SizedBox(
child: CircularProgressIndicator(),
width: 60,
height: 60,
),
];
}
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
);
},
),
]// This trailing comma makes auto-formatting nicer for build methods.
)));
}
getHomePageBody(BuildContext context) {
final _screenSize = MediaQuery.of(context).size;
return Container(
height: _screenSize.height * 0.85,
child:
new GridView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: alleyes.length,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount (crossAxisCount: 3),
itemBuilder: (context,index){
return _getItemUI(context,index);
}));
}
Widget _getItemUI(BuildContext context, int index) {
return Container(
child: Card(
child:
new Image.network(alleyes[index].link, fit: BoxFit.cover),
),
);
}
}
so what could i use here so that the back pressing functionality can be achieved?