android – Flutter: How do I create a widget that incorporates distinct cases of an inventory


I will attempt my finest to clarify my drawback, however the phrasing is tough as you’ll be able to inform from the title. I’ve an inventory, todayExercises, that’s edited by every occasion of the widget DayExercisePage, slightly than the widget enhancing every occasion of the record.

class _DayExercisePageState extends State<DayExercisePage> {
    Checklist<Train> todaysExercises = [];

  //Saving chicanery

  // Load information from shared preferences
  Future<Checklist<Train>> loadData() async {
    last SharedPreferences prefs = await SharedPreferences.getInstance();
    last String? myDataString = prefs.getString('todaysExercises');
    if (myDataString != null) {
      last Checklist<dynamic> myDataJson = jsonDecode(myDataString);
      todaysExercises =
          myDataJson.map((dynamic merchandise) => Train.fromMap(merchandise)).toList();
    }
    return todaysExercises;
  }

  // Save Todays exercieses to shared preferences
  Future<void> saveData() async {
    last SharedPreferences prefs = await SharedPreferences.getInstance();
    last Checklist<dynamic> myDataJson =
        todaysExercises.map((Train train) => train.toMap()).toList();
    last String myDataString = jsonEncode(myDataJson);
    await prefs.setString('todaysExercises', myDataString);
  }

Every tile within the following picture has its personal occasion of DayExercisePage which it routes to when clicked.
enter image description here

Nevertheless, every occasion of DayExercisePage builds with the identical todaysExercises record.

enter image description here

How do I make the todayExercises record distinctive to every DayExercisePage?

See also  Introducing Kodeco — the New raywenderlich.com

Leave a Reply