Advertisement
Guest User

AdsScreen

a guest
Sep 12th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.02 KB | None | 0 0
  1. import '../helpers/imports.dart';
  2.  
  3.  
  4. class AdsScreen extends StatelessWidget {
  5.   const AdsScreen({super.key});
  6.  
  7.   // change duration
  8.   Future<void> addPlay(int duration) async {
  9.     await Future.delayed(Duration(seconds: duration));
  10.   }
  11.  
  12.   @override
  13.   Widget build(BuildContext context) {
  14.     //final double width = MediaQuery.of(context).size.width;
  15.     print('Building AdsScreen');
  16.     final adsProv = Provider.of<AdsProvider>(context, listen: false);
  17.     return FutureBuilder(
  18.       future: adsProv.getAds(),
  19.       builder: (context, snapshot) {
  20.         if (snapshot.connectionState == ConnectionState.waiting) {
  21.           return const Center(child: CircularProgressIndicator());
  22.         } else if (snapshot.hasError) {
  23.           return const LoginErrorScreen();
  24.         } else if (snapshot.connectionState == ConnectionState.done &&
  25.             adsProv.ads.isEmpty) {
  26.           adsProv.screenTypeAdd = false;
  27.           return const Splitter();
  28.         }
  29.         // Future has loaded with no errors and there are adds to display
  30.         Add add = adsProv.ads[adsProv.currentIndex];
  31.  
  32.         if (add.type == 0) {
  33.           return FutureBuilder(
  34.             future: addPlay(add.displayTime!),
  35.             builder: (context, snapshot) {
  36.               if (snapshot.connectionState == ConnectionState.done) {
  37.                 print('Pushing from AdsScreen');
  38.                 adsProv.screenTypeAdd = false;
  39.                 adsProv.incrementCurentIndex();
  40.                 return const Splitter();
  41.               }
  42.               return LayoutBuilder(
  43.                 builder: (context, constraints) => SizedBox(
  44.                   width: constraints.maxWidth,
  45.                   height: constraints.maxHeight,
  46.                   child: Image.network(
  47.                     adsProv.ads[adsProv.currentIndex].adUrl!,
  48.                     fit: BoxFit.cover,
  49.                   ),
  50.                 ),
  51.               );
  52.             },
  53.           );
  54.         } else {
  55.           return const VideoPlayerScreen();
  56.         }
  57.       },
  58.     );
  59.   }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement