We will explore four ways to go back to previous routes.
First way we will explore the native way. Flutter AppBar takes IconButton or any widget that takes onPress or onTap event.
Inside event set
Navigator.pop(context);
And you are good to go. So the actual code would look like this
onPressed: () {
Navigator.pop(context);
},
Second way If you use Getx then just use
Get.back()
Inside your onTap or onPressed method()
Third way is using the BackButton() widget in Flutter.
Fourth way is using BLoC
With BLoC you can also go to previous screen or page.
You just need to send a callback function to onTap or onPressed and you are good to go.
appBar: AppBar(
leading: BackButton(
onPressed: ()=>BlocProvider.of<WorkoutCubit>(context).goHome(),
),
),
Now this onPressed event could be in any custom widget or buttons.
BLoC App
Getx App