|
| 1 | +import 'package:dataconnect/movies_connector/movies.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | + |
| 4 | +class ActorDetail extends StatefulWidget { |
| 5 | + const ActorDetail({super.key, required this.actorId}); |
| 6 | + |
| 7 | + final String actorId; |
| 8 | + |
| 9 | + @override |
| 10 | + State<ActorDetail> createState() => _ActorDetailState(); |
| 11 | +} |
| 12 | + |
| 13 | +class _ActorDetailState extends State<ActorDetail> { |
| 14 | + bool loading = true; |
| 15 | + GetActorByIdActor? actor; |
| 16 | + @override |
| 17 | + void initState() { |
| 18 | + super.initState(); |
| 19 | + MoviesConnector.instance |
| 20 | + .getActorById(id: widget.actorId) |
| 21 | + .execute() |
| 22 | + .then((value) { |
| 23 | + setState(() { |
| 24 | + loading = false; |
| 25 | + actor = value.data.actor; |
| 26 | + }); |
| 27 | + }); |
| 28 | + } |
| 29 | + |
| 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 | + Expanded( |
| 54 | + child: Padding( |
| 55 | + padding: const EdgeInsets.fromLTRB(15, 0, 0, 0), |
| 56 | + // child: Column(children: [Text(actor!.info!)]), |
| 57 | + )) |
| 58 | + ]), |
| 59 | + Row( |
| 60 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 61 | + children: [ |
| 62 | + // TODO(mtewani): Check if the movie has been watched by the user |
| 63 | + OutlinedButton.icon( |
| 64 | + onPressed: () { |
| 65 | + // TODO(mtewani): Check if user is logged in. |
| 66 | + }, |
| 67 | + icon: const Icon(Icons.favorite), |
| 68 | + label: const Text('Add To Favorites'), |
| 69 | + ) |
| 70 | + ], |
| 71 | + ) |
| 72 | + ]; |
| 73 | + } |
| 74 | + |
| 75 | + @override |
| 76 | + Widget build(BuildContext context) { |
| 77 | + return Scaffold( |
| 78 | + body: SafeArea( |
| 79 | + child: actor == null |
| 80 | + ? const Column( |
| 81 | + mainAxisAlignment: MainAxisAlignment.center, |
| 82 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 83 | + children: [CircularProgressIndicator()], |
| 84 | + ) |
| 85 | + : Padding( |
| 86 | + padding: const EdgeInsets.all(30), |
| 87 | + child: SingleChildScrollView( |
| 88 | + child: Column( |
| 89 | + children: [..._buildActorInfo()], |
| 90 | + )))), |
| 91 | + ); |
| 92 | + } |
| 93 | +} |
0 commit comments