|
1 | | -import 'package:dataconnect/movie_state.dart'; |
2 | | -import 'package:dataconnect/movies_connector/movies.dart'; |
3 | | -import 'package:dataconnect/widgets/list_movies.dart'; |
4 | 1 | import 'package:flutter/material.dart'; |
5 | 2 |
|
6 | | -class ActorDetail extends StatefulWidget { |
7 | | - const ActorDetail({super.key, required this.actorId}); |
| 3 | +import 'movie_state.dart'; |
| 4 | +import 'widgets/list_movies.dart'; |
8 | 5 |
|
9 | | - final String actorId; |
10 | | - |
11 | | - @override |
12 | | - State<ActorDetail> createState() => _ActorDetailState(); |
13 | | -} |
14 | | - |
15 | | -class _ActorDetailState extends State<ActorDetail> { |
16 | | - bool loading = true; |
17 | | - GetActorByIdActor? actor; |
18 | | - @override |
19 | | - void initState() { |
20 | | - super.initState(); |
21 | | - |
22 | | - MovieState.getActorById(widget.actorId).then((value) { |
23 | | - setState(() { |
24 | | - loading = false; |
25 | | - actor = value.data.actor; |
26 | | - }); |
27 | | - }); |
28 | | - } |
| 6 | +class ActorDetail extends StatelessWidget { |
| 7 | + const ActorDetail({ |
| 8 | + super.key, |
| 9 | + required this.actorId, |
| 10 | + }); |
29 | 11 |
|
30 | | - _buildActorInfo() { |
31 | | - return [ |
32 | | - Align( |
33 | | - alignment: Alignment.centerLeft, |
34 | | - child: Container( |
35 | | - child: Text( |
36 | | - actor!.name, |
37 | | - style: const TextStyle(fontSize: 30), |
38 | | - ), |
39 | | - )), |
40 | | - Row( |
41 | | - mainAxisAlignment: MainAxisAlignment.start, |
42 | | - crossAxisAlignment: CrossAxisAlignment.start, |
43 | | - children: [ |
44 | | - Expanded( |
45 | | - child: AspectRatio( |
46 | | - aspectRatio: 9 / 16, // 9:16 aspect ratio for the image |
47 | | - child: Image.network( |
48 | | - actor!.imageUrl, |
49 | | - fit: BoxFit.cover, |
50 | | - ), |
51 | | - ), |
52 | | - ), |
53 | | - ]), |
54 | | - ]; |
55 | | - } |
56 | | - |
57 | | - Widget _buildMainRoles() { |
58 | | - return ListMovies( |
59 | | - movies: MovieState.convertMainActorDetail(actor!.mainActors), |
60 | | - title: "Main Roles"); |
61 | | - } |
62 | | - |
63 | | - Widget _buildSupportingRoles() { |
64 | | - return ListMovies( |
65 | | - movies: |
66 | | - MovieState.convertSupportingActorDetail(actor!.supportingActors), |
67 | | - title: "Supporting Roles"); |
68 | | - } |
| 12 | + final String actorId; |
69 | 13 |
|
70 | 14 | @override |
71 | 15 | Widget build(BuildContext context) { |
72 | | - return Scaffold( |
73 | | - body: SafeArea( |
74 | | - child: actor == null |
75 | | - ? const Column( |
76 | | - mainAxisAlignment: MainAxisAlignment.center, |
77 | | - crossAxisAlignment: CrossAxisAlignment.center, |
78 | | - children: [CircularProgressIndicator()], |
79 | | - ) |
80 | | - : Padding( |
81 | | - padding: const EdgeInsets.all(30), |
82 | | - child: SingleChildScrollView( |
83 | | - child: Column( |
| 16 | + return FutureBuilder( |
| 17 | + future: MovieState.getActorById(actorId), |
| 18 | + builder: (context, snapshot) { |
| 19 | + final actor = snapshot.data?.data.actor; |
| 20 | + final loading = snapshot.connectionState == ConnectionState.waiting; |
| 21 | + return Scaffold( |
| 22 | + body: SafeArea( |
| 23 | + child: () { |
| 24 | + if (actor == null || loading) { |
| 25 | + return const Center( |
| 26 | + child: CircularProgressIndicator(), |
| 27 | + ); |
| 28 | + } |
| 29 | + return Padding( |
| 30 | + padding: const EdgeInsets.all(30), |
| 31 | + child: SingleChildScrollView( |
| 32 | + child: Column( |
84 | 33 | children: [ |
85 | | - ..._buildActorInfo(), |
86 | | - _buildMainRoles(), |
87 | | - _buildSupportingRoles() |
| 34 | + Align( |
| 35 | + alignment: Alignment.centerLeft, |
| 36 | + child: Text( |
| 37 | + actor.name, |
| 38 | + style: const TextStyle(fontSize: 30), |
| 39 | + )), |
| 40 | + Row( |
| 41 | + mainAxisAlignment: MainAxisAlignment.start, |
| 42 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 43 | + children: [ |
| 44 | + Expanded( |
| 45 | + child: AspectRatio( |
| 46 | + aspectRatio: |
| 47 | + 9 / 16, // 9:16 aspect ratio for the image |
| 48 | + child: Image.network( |
| 49 | + actor.imageUrl, |
| 50 | + fit: BoxFit.cover, |
| 51 | + ), |
| 52 | + ), |
| 53 | + ), |
| 54 | + ], |
| 55 | + ), |
| 56 | + ListMovies( |
| 57 | + movies: MovieState.convertMainActorDetail( |
| 58 | + actor.mainActors, |
| 59 | + ), |
| 60 | + title: "Main Roles", |
| 61 | + ), |
| 62 | + ListMovies( |
| 63 | + movies: MovieState.convertSupportingActorDetail( |
| 64 | + actor.supportingActors, |
| 65 | + ), |
| 66 | + title: "Supporting Roles", |
| 67 | + ), |
88 | 68 | ], |
89 | | - )))), |
| 69 | + ), |
| 70 | + ), |
| 71 | + ); |
| 72 | + }(), |
| 73 | + ), |
| 74 | + ); |
| 75 | + }, |
90 | 76 | ); |
91 | 77 | } |
92 | 78 | } |
0 commit comments