Skip to content

Commit

Permalink
user details
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanbicoi committed Jan 23, 2024
1 parent 3fd7dc7 commit 45b865d
Show file tree
Hide file tree
Showing 22 changed files with 5,773 additions and 213 deletions.
5,246 changes: 5,246 additions & 0 deletions __FLUTTER_DEV_LOG__

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions flutter_jank_metrics_03.json

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions lib/models/base_model.dart

This file was deleted.

115 changes: 78 additions & 37 deletions lib/models/food_list_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,110 @@ FoodList foodListFromJson(String str) => FoodList.fromJson(json.decode(str));
String foodListToJson(FoodList data) => json.encode(data.toJson());

class FoodList {
int id;
String title;
String description;
String imageUrl;
int authorId;
bool? isFavourite;
List<FoodListFood> foods;
int id;
String title;
String description;
String imageUrl;
int authorId;
List<FoodListFood>? foods;
Author? author;
bool isFavourite;

FoodList({
required this.id,
required this.title,
required this.description,
required this.imageUrl,
required this.authorId,
this.isFavourite,
required this.foods,
});
FoodList({
required this.id,
required this.title,
required this.description,
required this.imageUrl,
required this.authorId,
this.foods,
this.author,
required this.isFavourite,
});

factory FoodList.fromJson(Map<String, dynamic> json) => FoodList(
factory FoodList.fromJson(Map<String, dynamic> json) => FoodList(
id: json["id"],
title: json["title"],
description: json["description"],
imageUrl: json["imageUrl"],
authorId: json["authorId"],
isFavourite: json["isFavourite"],
foods: List<FoodListFood>.from(json["foods"].map((x) => FoodListFood.fromJson(x))),
);
foods: json["foods"] != null
? List<FoodListFood>.from(
json["foods"].map((x) => FoodListFood.fromJson(x)))
: null,
author: json["author"] != null ? Author.fromJson(json["author"]) : null,
isFavourite: json["isFavourite"] ?? false,
);

Map<String, dynamic> toJson() => {
Map<String, dynamic> toJson() => {
"id": id,
"title": title,
"description": description,
"imageUrl": imageUrl,
"authorId": authorId,
"foods": foods != null
? List<dynamic>.from(foods!.map((x) => x.toJson()))
: null,
"author": author?.toJson(),
"isFavourite": isFavourite,
"foods": List<dynamic>.from(foods.map((x) => x.toJson())),
};
};
}

class Author {
int id;
String name;
String imageUrl;
int followers;
int following;

Author({
required this.id,
required this.name,
required this.imageUrl,
required this.followers,
required this.following,
});

factory Author.fromJson(Map<String, dynamic> json) => Author(
id: json["id"],
name: json["name"],
imageUrl: json["imageUrl"],
followers: json["followers"],
following: json["following"],
);

Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"imageUrl": imageUrl,
"followers": followers,
"following": following,
};
}

class FoodListFood {
int id;
String title;
List<String> images;
String body;
int id;
String title;
List<String> images;
String body;

FoodListFood({
required this.id,
required this.title,
required this.images,
required this.body,
});
FoodListFood({
required this.id,
required this.title,
required this.images,
required this.body,
});

factory FoodListFood.fromJson(Map<String, dynamic> json) => FoodListFood(
factory FoodListFood.fromJson(Map<String, dynamic> json) => FoodListFood(
id: json["id"],
title: json["title"],
images: List<String>.from(json["images"].map((x) => x)),
body: json["body"],
);
);

Map<String, dynamic> toJson() => {
Map<String, dynamic> toJson() => {
"id": id,
"title": title,
"images": List<dynamic>.from(images.map((x) => x)),
"body": body,
};
};
}
37 changes: 30 additions & 7 deletions lib/models/user_model.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
import 'package:fooderapp/models/base_model.dart';
import 'dart:convert';

class User implements BaseModel {
int? id;
import 'package:fooderapp/models/food_list_model.dart';

User userFromJson(String str) => User.fromJson(json.decode(str));

String userToJson(User data) => json.encode(data.toJson());

class User {
int id;
String name;
String? bio;
String bio;
String? imageUrl;
List<FoodListFood> foods;
List<FoodList> foodLists;
int followers;
int following;

User({
this.id,
required this.id,
required this.name,
this.bio,
required this.bio,
this.imageUrl,
required this.foods,
required this.foodLists,
required this.followers,
required this.following,
});

factory User.fromJson(Map<String, dynamic> json) => User(
id: json["id"],
name: json["name"],
bio: json["bio"],
imageUrl: json["imageUrl"],
foods: List<FoodListFood>.from(
json["foods"].map((x) => FoodListFood.fromJson(x))),
foodLists: List<FoodList>.from(
json["foodLists"].map((x) => FoodList.fromJson(x))),
followers: json["followers"],
following: json["following"],
);

@override
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"bio": bio,
"imageUrl": imageUrl,
"foods": List<dynamic>.from(foods.map((x) => x.toJson())),
"foodLists": List<dynamic>.from(foodLists.map((x) => x.toJson())),
"followers": followers,
"following": following,
};
}
79 changes: 49 additions & 30 deletions lib/pages/food_list_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import 'package:fooderapp/config/colors/colors.dart';
import 'package:fooderapp/config/constants.dart';
import 'package:fooderapp/models/food_list_model.dart';
import 'package:fooderapp/services/food_list_service.dart';
import 'package:fooderapp/utils/food_list_builder.dart';
import 'package:fooderapp/utils/helpers.dart';
import 'package:fooderapp/widgets/album_footer_widget.dart';
import 'package:fooderapp/widgets/food_widget.dart';
import 'package:fooderapp/widgets/food_title.dart';
import 'package:fooderapp/widgets/user_widget.dart';

class FoodListDetailsPage extends StatefulWidget {
final int id;
Expand All @@ -16,14 +17,6 @@ class FoodListDetailsPage extends StatefulWidget {
}

class _FoodListDetailsPageState extends State<FoodListDetailsPage> {
late Future<FoodList>? _future;
bool _isFavourite = false;
@override
void initState() {
super.initState();
_future = getFoodList(widget.id);
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -34,7 +27,7 @@ class _FoodListDetailsPageState extends State<FoodListDetailsPage> {
),
body: SafeArea(
child: FutureBuilder(
future: _future,
future: getFoodList(widget.id),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator(); // Show loading indicator
Expand All @@ -43,7 +36,6 @@ class _FoodListDetailsPageState extends State<FoodListDetailsPage> {
return Text('Error: ${snapshot.error}');
} else {
FoodList foodList = snapshot.data;
_isFavourite = foodList.isFavourite ?? false;
return Stack(
children: [
Padding(
Expand All @@ -53,17 +45,33 @@ class _FoodListDetailsPageState extends State<FoodListDetailsPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Album cover
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 250,
width: 250,
child: Image.network(foodList.imageUrl),
Center(
child: Container(
padding:
const EdgeInsets.fromLTRB(0, 10, 0, 0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color:
Colors.greenAccent.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 10,
offset: const Offset(0.5, 0.5),
),
],
),
],
height: 300,
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: Image.network(
foodList.imageUrl,
fit: BoxFit.cover,
),
),
),
),
const SizedBox(height: 10),
UserWidget(foodList.author!),
// Album name
Text(
foodList.title,
Expand All @@ -86,13 +94,11 @@ class _FoodListDetailsPageState extends State<FoodListDetailsPage> {
children: <Widget>[
IconButton(
onPressed: () async {
await favoriteFoodList(
widget.id, !_isFavourite);
setState(() {
_isFavourite = !_isFavourite;
});
await favoriteFoodList(widget.id,
!foodList.isFavourite);
setState(() {});
},
icon: _isFavourite
icon: foodList.isFavourite
? favouriteIcon
: unfavouriteIcon),
],
Expand All @@ -101,17 +107,30 @@ class _FoodListDetailsPageState extends State<FoodListDetailsPage> {
),
const VerticalSpacer(height: 5),
ListView.separated(
primary: false,
shrinkWrap: true,
itemBuilder: (context, index) =>
FoodWidget(foodList.foods[index]),
itemCount: foodList.foods.length,
itemBuilder: (context, index) {
final food = foodList.foods![index];
return FoodTile(food.id, food.title,
food.images, food.body);
},
itemCount: foodList.foods!.length,
separatorBuilder: (_, __) =>
const VerticalSpacer(height: 10),
),

const VerticalSpacer(height: 10),
// Album footer
const AlbumFooter()
const Text(
"You might also like",
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
const VerticalSpacer(height: 8),
SizedBox(
height: 200,
child: foodListBuilder(getFoodLists()),
)
],
),
),
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:fooderapp/pages/detail_dish_screen.dart';
import 'package:fooderapp/pages/home_page_content_screen.dart';
import 'package:fooderapp/pages/library_page.dart';
import 'package:fooderapp/pages/newsfeed_screen.dart';
import 'package:fooderapp/pages/search_screen.dart';

Expand All @@ -18,7 +19,7 @@ class _HomePageState extends State<HomePage> {
HomePageContent(),
NewsFeedScreen(),
SearchScreen(),
//DetailsDishScreen(),
LibraryPage(),
];


Expand Down
6 changes: 3 additions & 3 deletions lib/pages/home_page_content_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:fooderapp/models/food_list_model.dart';
import 'package:fooderapp/services/food_list_service.dart';
import 'package:fooderapp/theme/font_theme.dart';
import 'package:fooderapp/utils/helpers.dart';
import 'package:fooderapp/widgets/home_big_tile.dart';
import 'package:fooderapp/widgets/food_list_tile.dart';
import 'package:fooderapp/widgets/home_page_recent_tile.dart';

class HomePageContent extends StatefulWidget {
Expand Down Expand Up @@ -157,7 +157,7 @@ class _HomePageContentState extends State<HomePageContent> {
separatorBuilder: (BuildContext context, int index) =>
const HorizontalSpacer(width: 20),
itemBuilder: (context, index) =>
HomeBigTile(foodList[index]),
FoodListTile(foodList[index]),
);
}
},
Expand Down Expand Up @@ -186,7 +186,7 @@ class _HomePageContentState extends State<HomePageContent> {
separatorBuilder: (BuildContext context, int index) =>
const HorizontalSpacer(width: 20),
itemBuilder: (context, index) =>
HomeBigTile(foodList[index]),
FoodListTile(foodList[index]),
);
}
},
Expand Down
Loading

0 comments on commit 45b865d

Please sign in to comment.