You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			102 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			102 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Dart
		
	
| import 'dart:async';
 | |
| import 'dart:ui' as ui;
 | |
| 
 | |
| import 'package:easy_localization/easy_localization.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| import 'package:mohem_flutter_app/classes/colors.dart';
 | |
| import 'package:mohem_flutter_app/config/routes.dart';
 | |
| import 'package:mohem_flutter_app/extensions/string_extensions.dart';
 | |
| import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
 | |
| import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
 | |
| import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart';
 | |
| import 'package:provider/provider.dart';
 | |
| import 'package:video_player/video_player.dart';
 | |
| 
 | |
| class SponsorVideoScreen extends StatelessWidget {
 | |
|   const SponsorVideoScreen({Key? key}) : super(key: key);
 | |
| 
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     MarathonProvider provider = context.watch<MarathonProvider>();
 | |
|     return WillPopScope(
 | |
|       onWillPop: () {
 | |
|         provider.videoController.pause();
 | |
|         provider.disposeVideoPlayer();
 | |
|         provider.sponsorsSecondsCounter = 0;
 | |
|         provider.totalSponsorVideoSeconds = 0;
 | |
|         provider.timerForSponsorVideo.cancel();
 | |
|         return Future<bool>.value(true);
 | |
|       },
 | |
|       child: Scaffold(
 | |
|         backgroundColor: MyColors.black,
 | |
|         body: SafeArea(
 | |
|           child: Stack(
 | |
|             children: <Widget>[
 | |
|               Align(
 | |
|                 child: provider.videoController.value.isInitialized
 | |
|                     ? AspectRatio(
 | |
|                         aspectRatio: provider.videoController.value.aspectRatio,
 | |
|                         child: VideoPlayer(provider.videoController),
 | |
|                       )
 | |
|                     : Container(color: Colors.white),
 | |
|               ),
 | |
|               Align(
 | |
|                 alignment: Alignment.topRight,
 | |
|                 child: Container(
 | |
|                   decoration: BoxDecoration(
 | |
|                     color: MyColors.white,
 | |
|                     shape: provider.totalSponsorVideoSeconds == 0 ? BoxShape.circle : BoxShape.rectangle,
 | |
|                     borderRadius: provider.totalSponsorVideoSeconds == 0 ? null : BorderRadius.circular(15),
 | |
|                   ),
 | |
|                   padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 8),
 | |
|                   child: provider.totalSponsorVideoSeconds == 0
 | |
|                       ? InkWell(
 | |
|                           onTap: () {
 | |
|                             Navigator.pushReplacementNamed(context, AppRoutes.marathonIntroScreen);
 | |
|                             provider.videoController.pause();
 | |
|                             provider.disposeVideoPlayer();
 | |
|                             provider.sponsorsSecondsCounter = 0;
 | |
|                             provider.totalSponsorVideoSeconds = 0;
 | |
|                             provider.timerForSponsorVideo.cancel();
 | |
|                           },
 | |
|                           child: const Icon(Icons.close, size: 12),
 | |
|                         )
 | |
|                       : Directionality(
 | |
|                           textDirection: ui.TextDirection.ltr,
 | |
|                           child: ("${LocaleKeys.ourSponsor.tr()} ${provider.totalSponsorVideoSeconds < 10 ? "0" : ""}${provider.totalSponsorVideoSeconds}").toText12(color: MyColors.darkTextColor),
 | |
|                         ),
 | |
|                 ),
 | |
|               ).paddingOnly(top: 20, right: 18),
 | |
| 
 | |
|               //TODO: WE WILL INCREASE THIS 2 BEFORE GOING LIVE
 | |
|               provider.sponsorsSecondsCounter >= 2
 | |
|                   ? Align(
 | |
|                       alignment: Alignment.topLeft,
 | |
|                       child: InkWell(
 | |
|                         onTap: () {
 | |
|                           Navigator.pushReplacementNamed(context, AppRoutes.marathonIntroScreen);
 | |
|                           provider.videoController.pause();
 | |
|                           provider.disposeVideoPlayer();
 | |
|                           provider.sponsorsSecondsCounter = 0;
 | |
|                           provider.totalSponsorVideoSeconds = 0;
 | |
|                           provider.timerForSponsorVideo.cancel();
 | |
|                         },
 | |
|                         child: Container(
 | |
|                           decoration: BoxDecoration(color: MyColors.white, borderRadius: BorderRadius.circular(15)),
 | |
|                           padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 6),
 | |
|                           child: Directionality(
 | |
|                             textDirection: ui.TextDirection.ltr,
 | |
|                             child: LocaleKeys.skip.tr().toText11(color: MyColors.darkTextColor),
 | |
|                           ),
 | |
|                         ),
 | |
|                       ),
 | |
|                     ).paddingOnly(top: 20, left: 18)
 | |
|                   : const SizedBox(),
 | |
|             ],
 | |
|           ),
 | |
|         ),
 | |
|       ),
 | |
|     );
 | |
|   }
 | |
| }
 |