delay / flutter_starter

MIT License
422 stars 146 forks source link

Sample List & Details Pages #17

Closed jtkeyva closed 3 years ago

jtkeyva commented 3 years ago

Hello, wondering if you can provide a sample that includes a real world scenario to see how you structure and list things.

One example would be a list of restaurants. When you click on the name of the restaurant you get a details page with: Name, Address, Phone Number, Photos, Lat/Lon, Rating etc.

Just curious how you would do things with your starter and feel it would help people learn by example.

Thanks

delay commented 3 years ago

You can look at how I handle info for storing the users email, profile pic etc on firebase. It would be similar to that. I don't plan to create other examples at this time. This is mainly just to give users a starting point when building their own app. There are a lot of videos on youtube that provide tutorials for doing something similar to what you want.

delay commented 3 years ago

This guy has a lot of good getx videos. https://youtu.be/PQ_sxDjPUzU

jtkeyva commented 3 years ago

Thanks. Yeah I like those vids, however his models are a bit different than yours. Curious how to handle maps & arrays with your setup but I'll keep chipping away

delay commented 3 years ago

Oops sorry I missed your comment.
Here is an example of how I would do a model with a list of items...

//Embedded Class of AppSettings
class WorkoutOption {
  String id;
  String name;
  String description;
  String color;
  List<ExerciseOption> exercises;

  WorkoutOption(
      {this.id, this.name, this.description, this.color, this.exercises});

  WorkoutOption.fromMap(Map data) {
    id = data['id'];
    name = data['name'] ?? '';
    description = data['description'] ?? '';
    color = data['color'] ?? '';
    exercises = (data['exercises'] as List ?? [])
        .map((v) => ExerciseOption.fromMap(v))
        .toList();
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
        "description": description,
        "color": color,
        "exercises": List<dynamic>.from(exercises.map((x) => x.toJson())),
      };
}

//Embedded Class of WorkoutOption
class ExerciseOption {
  String name;
  String color;
  int series;
  int order;

  ExerciseOption({this.name, this.color, this.series, this.order});

  ExerciseOption.fromMap(Map data) {
    name = data['name'] ?? '';
    color = data['color'] ?? '';
    series = data['series'];
    order = data['order'];
  }

  Map<String, dynamic> toJson() => {
        "name": name,
        "color": color,
        "series": series,
        "order": order,
      };
}
jtkeyva commented 3 years ago

thanks for that!