diff options
Diffstat (limited to 'lib/screens/popular_screen.dart')
-rw-r--r-- | lib/screens/popular_screen.dart | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/screens/popular_screen.dart b/lib/screens/popular_screen.dart new file mode 100644 index 0000000..07ca70e --- /dev/null +++ b/lib/screens/popular_screen.dart @@ -0,0 +1,55 @@ +import 'package:flutter/material.dart'; +import 'package:pmsna1/models/popular.dart'; +import 'package:pmsna1/network/popular_api.dart'; +import 'package:pmsna1/widgets/loading_modal_widget.dart'; +import 'package:pmsna1/widgets/popular_item.dart'; + +class PopularScreen extends StatefulWidget { + const PopularScreen({super.key}); + + @override + State<PopularScreen> createState() => _PopularScreenState(); +} + +class _PopularScreenState extends State<PopularScreen> { + PopularApi? popularApi; + + @override + void initState() { + super.initState(); + popularApi = PopularApi(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('Películas populares')), + body: FutureBuilder( + future: popularApi!.getAllPopular(), + builder: (context, AsyncSnapshot<List<Popular>?> snapshot) { + if (snapshot.hasData) { + return GridView.builder( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + childAspectRatio: .9, + mainAxisSpacing: 10, + crossAxisSpacing: 10, + ), + itemCount: snapshot.data != null ? snapshot.data!.length : 0, + itemBuilder: (context, index) { + return PopularItem(snapshot.data![index]); + }, + ); + } else if (snapshot.hasError) { + print(snapshot.error); + return const Center( + child: Text('Ocurrió un error'), + ); + } else { + return const LoadingModal(); + } + }, + ), + ); + } +} |