|
1 | 1 | import 'package:flutter/material.dart'; |
2 | 2 |
|
3 | 3 | class Actor { |
4 | | - Actor({required this.imageUrl, required this.name, required this.id}); |
| 4 | + Actor({ |
| 5 | + required this.imageUrl, |
| 6 | + required this.name, |
| 7 | + required this.id, |
| 8 | + }); |
5 | 9 | String imageUrl; |
6 | 10 | String name; |
7 | 11 | String id; |
8 | 12 | } |
9 | 13 |
|
10 | | -class ListActors extends StatefulWidget { |
11 | | - const ListActors({super.key, required this.actors, required this.title}); |
| 14 | +class ListActors extends StatelessWidget { |
| 15 | + const ListActors({ |
| 16 | + super.key, |
| 17 | + required this.actors, |
| 18 | + required this.title, |
| 19 | + }); |
12 | 20 | final List<Actor> actors; |
13 | 21 | final String title; |
14 | 22 |
|
15 | | - @override |
16 | | - State<ListActors> createState() => _ListActorsState(); |
17 | | -} |
18 | | - |
19 | | -class _ListActorsState extends State<ListActors> { |
20 | | - _buildActor(Actor actor) { |
21 | | - return SizedBox( |
22 | | - width: 100, |
23 | | - child: Column( |
24 | | - mainAxisAlignment: MainAxisAlignment.start, |
25 | | - crossAxisAlignment: CrossAxisAlignment.center, |
26 | | - children: [ |
27 | | - CircleAvatar( |
28 | | - radius: 30, |
29 | | - child: ClipOval(child: Image.network(actor.imageUrl))), |
30 | | - Text( |
31 | | - actor.name, |
32 | | - overflow: TextOverflow.ellipsis, |
33 | | - ) |
34 | | - ])); |
35 | | - } |
36 | | - |
37 | | - _buildActorsList() { |
38 | | - return SizedBox( |
39 | | - height: 125, |
40 | | - child: Column( |
41 | | - mainAxisAlignment: MainAxisAlignment.start, |
42 | | - crossAxisAlignment: CrossAxisAlignment.start, |
43 | | - children: [ |
44 | | - Text( |
45 | | - widget.title, |
46 | | - style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), |
47 | | - ), |
48 | | - Expanded( |
49 | | - child: ListView.builder( |
50 | | - scrollDirection: Axis.horizontal, |
51 | | - itemBuilder: (context, index) { |
52 | | - return _buildActor(widget.actors[index]); |
53 | | - }, |
54 | | - itemCount: widget.actors.length, |
55 | | - )) |
56 | | - ], |
57 | | - )); |
58 | | - } |
59 | | - |
60 | 23 | @override |
61 | 24 | Widget build(BuildContext context) { |
62 | | - return _buildActorsList(); |
| 25 | + return SizedBox( |
| 26 | + height: 125, |
| 27 | + child: Column( |
| 28 | + mainAxisAlignment: MainAxisAlignment.start, |
| 29 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 30 | + children: [ |
| 31 | + Text( |
| 32 | + title, |
| 33 | + style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), |
| 34 | + ), |
| 35 | + Expanded( |
| 36 | + child: ListView.builder( |
| 37 | + scrollDirection: Axis.horizontal, |
| 38 | + itemBuilder: (context, index) { |
| 39 | + final actor = actors[index]; |
| 40 | + return SizedBox( |
| 41 | + width: 100, |
| 42 | + child: Column( |
| 43 | + mainAxisAlignment: MainAxisAlignment.start, |
| 44 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 45 | + children: [ |
| 46 | + CircleAvatar( |
| 47 | + radius: 30, |
| 48 | + child: ClipOval(child: Image.network(actor.imageUrl))), |
| 49 | + Text( |
| 50 | + actor.name, |
| 51 | + overflow: TextOverflow.ellipsis, |
| 52 | + ) |
| 53 | + ], |
| 54 | + ), |
| 55 | + ); |
| 56 | + }, |
| 57 | + itemCount: actors.length, |
| 58 | + )) |
| 59 | + ], |
| 60 | + ), |
| 61 | + ); |
63 | 62 | } |
64 | 63 | } |
0 commit comments