Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/utilis/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class Utils {
static double averageRating(List<int> rating) {
var avgRating = 0;
for (int i = 0; i < rating.length; i++) {
avgRating = avgRating + rating[i];
}
return double.parse((avgRating / rating.length).toStringAsFixed(1));
}

static void fieldFocusChange(
BuildContext context,
FocusNode current,
Expand Down
43 changes: 36 additions & 7 deletions lib/view/homeview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mvvm/data/response/status.dart';
import 'package:mvvm/resources/component/colors.dart';
import 'package:mvvm/utilis/routes_name.dart';
import 'package:mvvm/utilis/utils.dart';
import 'package:mvvm/view_model/home_view_model.dart';
import 'package:mvvm/view_model/user_view_model.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -63,12 +64,14 @@ class _HomeScreenState extends State<HomeScreen> {
builder: (context, value, _) {
switch (value.moviesList.status) {
case Status.LOADING:
return CircularProgressIndicator();
return Center(child: CircularProgressIndicator());

case Status.ERROR:
return Text(
value.moviesList.message.toString(),
style: TextStyle(color: Colors.black),
return Center(
child: Text(
value.moviesList.message.toString(),
style: TextStyle(color: Colors.black),
),
);

case Status.COMPLETED:
Expand All @@ -77,9 +80,35 @@ class _HomeScreenState extends State<HomeScreen> {
value.moviesList.data!.movies!.length, // ⚠ Required
itemBuilder: (context, index) {
return Card(
child: Text(
'asdf',
style: TextStyle(color: Colors.black),
child: ListTile(
leading: Image.network(
value.moviesList.data!.movies![index].posterurl
.toString(),
errorBuilder: (context, error, stack) {
return Icon(Icons.error, color: Colors.red);
},
height: 40.h,
width: 40.w,
fit: BoxFit.cover,
),
title: Text(
value.moviesList.data!.movies![index].title
.toString(),
),
subtitle: Text(
value.moviesList.data!.movies![index].year.toString(),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
Utils.averageRating(
value.moviesList.data!.movies![index].ratings!,
).toStringAsFixed(1),
),
Icon(Icons.star, color: Colors.yellow),
],
),
),
);
},
Expand Down