1

I want to keep the view or session of some screens. For example, if I close the app, I can then go back to the last open screen.

I think this is possible using SharedPreferences, but I just know that SharedPreferences is for user data only. I would like to know some alternatives, thanks!

import 'package:flutter/material.dart';

class KeepScreen extends StatefulWidget {
  CKeepScreena({Key? key}) : super(key: key);

  @override
  State<CKeepScreen> createState() => _CKeepScreenState();
}

class _KeepScreenState extends State<KeepScreen> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
Carlos Peñaranda
  • 632
  • 1
  • 6
  • 19
  • you can use SharedPreferences. so every time the app closes you can save the pagename(statewidget name). next time app opens up, in the init route. you will pass the SharedPreference string value to the route. – brook yonas Jul 17 '22 at 19:24

1 Answers1

1

Using Shared Preferences like you said, you can do something like this:

  1. Every time that you navigate to a screen that you want to come back, you save this information on Shared prefs.
  2. When you init your app, you read the shared preferences to check the last page saved, and navigate again to this page. You can do this on your main() or inside another method called on app startup.