Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import '../helpers/imports.dart';
- class AdsScreen extends StatelessWidget {
- const AdsScreen({super.key});
- // change duration
- Future<void> addPlay(int duration) async {
- await Future.delayed(Duration(seconds: duration));
- }
- @override
- Widget build(BuildContext context) {
- //final double width = MediaQuery.of(context).size.width;
- print('Building AdsScreen');
- final adsProv = Provider.of<AdsProvider>(context, listen: false);
- return FutureBuilder(
- future: adsProv.getAds(),
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.waiting) {
- return const Center(child: CircularProgressIndicator());
- } else if (snapshot.hasError) {
- return const LoginErrorScreen();
- } else if (snapshot.connectionState == ConnectionState.done &&
- adsProv.ads.isEmpty) {
- adsProv.screenTypeAdd = false;
- return const Splitter();
- }
- // Future has loaded with no errors and there are adds to display
- Add add = adsProv.ads[adsProv.currentIndex];
- if (add.type == 0) {
- return FutureBuilder(
- future: addPlay(add.displayTime!),
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.done) {
- print('Pushing from AdsScreen');
- adsProv.screenTypeAdd = false;
- adsProv.incrementCurentIndex();
- return const Splitter();
- }
- return LayoutBuilder(
- builder: (context, constraints) => SizedBox(
- width: constraints.maxWidth,
- height: constraints.maxHeight,
- child: Image.network(
- adsProv.ads[adsProv.currentIndex].adUrl!,
- fit: BoxFit.cover,
- ),
- ),
- );
- },
- );
- } else {
- return const VideoPlayerScreen();
- }
- },
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement