summaryrefslogtreecommitdiff
path: root/lib/screens/popular_screen.dart
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-03-26 21:04:58 -0600
committerIván Ávalos <avalos@disroot.org>2023-03-26 21:04:58 -0600
commit4b7d33896879baba1435281f814766a80fbeecb2 (patch)
tree9cc37361f5a8ccffa5a4c4da20120b54b1649d69 /lib/screens/popular_screen.dart
parent68d54a5660e1c6651a604b078e78a2658ca61ea1 (diff)
downloadpmsna1-4b7d33896879baba1435281f814766a80fbeecb2.tar.gz
pmsna1-4b7d33896879baba1435281f814766a80fbeecb2.tar.bz2
pmsna1-4b7d33896879baba1435281f814766a80fbeecb2.zip
Added popular movies screen and Firebase support
Diffstat (limited to 'lib/screens/popular_screen.dart')
-rw-r--r--lib/screens/popular_screen.dart55
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();
+ }
+ },
+ ),
+ );
+ }
+}