summaryrefslogtreecommitdiff
path: root/lib/widgets/popular_list.dart
blob: 2422a381c406efeedee45ed77294c3c86a28f009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import 'package:flutter/material.dart';

import '../models/popular.dart';
import 'popular_item.dart';

class PopularList extends StatelessWidget {
  final List<Popular> popularList;
  final void Function(Popular popular, bool favorited) onFavorited;
  final void Function(Popular popular) onPressed;

  const PopularList(
    this.popularList, {
    super.key,
    required this.onFavorited,
    required this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: 2 / 3,
        mainAxisSpacing: 10,
        crossAxisSpacing: 10,
      ),
      itemCount: popularList.length,
      itemBuilder: (context, index) {
        return PopularItem(
          popularList[index],
          onFavorited: (favorited) =>
              onFavorited(popularList[index], favorited),
          onPressed: () => onPressed(popularList[index]),
        );
      },
    );
  }
}