import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'app_state.dart';


class FavoritePage extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
        var appState = context.watch<TindBookState>();
        var favorites = appState.favorites;

        return LayoutBuilder(builder: (context, constraints) {
            return Scaffold(
                backgroundColor: Colors.red[200],
                body: favorites.length > 0 ? ListView.builder(
                    padding: const EdgeInsets.all(8),
                    itemCount: favorites.length,
                    itemBuilder: (BuildContext context, int index){
                        return ListView(
                            padding: const EdgeInsets.all(8),
                            children: <Widget>[
                                Container(
                                    color: index%2 == 0 ? Colors.red[500] : Colors.red[400],
                                    child: Text(favorites[index]['title']),
                                ),
                                Container(
                                    color: index%2 == 0 ? Colors.red[500] : Colors.red[400],
                                    child: Text(favorites[index]['subtitle']),
                                ),
                                Container(
                                    color: index%2 == 0 ? Colors.red[500] : Colors.red[400],
                                    child: Text(favorites[index]['author']),
                                ),
                                Container(
                                    color: index%2 == 0 ? Colors.red[500] : Colors.red[400],
                                    child: Text(favorites[index]['published']),
                                ),
                                Container(
                                    color: index%2 == 0 ? Colors.red[500] : Colors.red[400],
                                    child: Text(favorites[index]['publisher']),
                                ),
                                Container(
                                    color: index%2 == 0 ? Colors.red[500] : Colors.red[400],
                                    child: Text(favorites[index]['description']),
                                ),
                                Container(
                                    color: index%2 == 0 ? Colors.red[500] : Colors.red[400],
                                    child: Text(favorites[index]['website']),
                                )
                            ]
                        );
                    }
                ) : Text("No favorites yet !"),
            );
        });
    }
}
