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.
		
		
		
		
		
			
		
			
	
	
		
			177 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Dart
		
	
		
		
			
		
	
	
			177 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Dart
		
	
| 
								 
											3 years ago
										 
									 | 
							
								import 'dart:ui' as ui;
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								import 'package:auto_size_text/auto_size_text.dart';
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								import 'package:easy_localization/easy_localization.dart';
							 | 
						||
| 
								 | 
							
								import 'package:flutter/material.dart';
							 | 
						||
| 
								 | 
							
								import 'package:flutter_countdown_timer/current_remaining_time.dart';
							 | 
						||
| 
								 | 
							
								import 'package:flutter_countdown_timer/flutter_countdown_timer.dart';
							 | 
						||
| 
								 | 
							
								import 'package:mohem_flutter_app/classes/colors.dart';
							 | 
						||
| 
								 | 
							
								import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								import 'package:mohem_flutter_app/main.dart';
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								class CountdownTimerForMainScreen extends StatelessWidget {
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  final int timeToMarathon;
							 | 
						||
| 
								 | 
							
								  final MarathonProvider provider;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  CountdownTimerForMainScreen({
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    Key? key,
							 | 
						||
| 
								 | 
							
								    required this.provider,
							 | 
						||
| 
								 | 
							
								    required this.timeToMarathon,
							 | 
						||
| 
								 | 
							
								  }) : super(key: key);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  final TextStyle styleTextHome = TextStyle(
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    color: MyColors.white.withOpacity(0.45),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    fontStyle: FontStyle.italic,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    fontWeight: FontWeight.w800,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    letterSpacing: -0.4,
							 | 
						||
| 
								 | 
							
								  );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  final TextStyle styleDigitHome = TextStyle(
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    height: 22 / 27,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    color: MyColors.white,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    fontSize: isTablet ? 30 : 15,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    fontStyle: FontStyle.italic,
							 | 
						||
| 
								 | 
							
								    letterSpacing: -1.44,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    fontWeight: FontWeight.bold,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  final TextStyle styleTextMarathon = const TextStyle(
							 | 
						||
| 
								 | 
							
								    fontSize: 10,
							 | 
						||
| 
								 | 
							
								    fontStyle: FontStyle.normal,
							 | 
						||
| 
								 | 
							
								    fontWeight: FontWeight.w600,
							 | 
						||
| 
								 | 
							
								    color: MyColors.grey57Color,
							 | 
						||
| 
								 | 
							
								    letterSpacing: -0.4,
							 | 
						||
| 
								 | 
							
								  );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  final TextStyle styleDigitMarathon = const TextStyle(
							 | 
						||
| 
								 | 
							
								    height: 23 / 24,
							 | 
						||
| 
								 | 
							
								    color: MyColors.darkTextColor,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    fontSize: 34,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    letterSpacing: -1.44,
							 | 
						||
| 
								 | 
							
								    fontWeight: FontWeight.bold,
							 | 
						||
| 
								 | 
							
								  );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  Widget buildSeparator() {
							 | 
						||
| 
								 | 
							
								    return AutoSizeText(
							 | 
						||
| 
								 | 
							
								      "  :  ",
							 | 
						||
| 
								 | 
							
								      maxFontSize: 24,
							 | 
						||
| 
								 | 
							
								      minFontSize: 20,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      style: styleDigitHome,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  Widget getTimeDigit(String text) {
							 | 
						||
| 
								 | 
							
								    return AutoSizeText(
							 | 
						||
| 
								 | 
							
								      text,
							 | 
						||
| 
								 | 
							
								      maxFontSize: 24,
							 | 
						||
| 
								 | 
							
								      minFontSize: 20,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      style: styleDigitHome,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  Widget getTimeText(String text) {
							 | 
						||
| 
								 | 
							
								    return AutoSizeText(
							 | 
						||
| 
								 | 
							
								      text,
							 | 
						||
| 
								 | 
							
								      minFontSize: 7,
							 | 
						||
| 
								 | 
							
								      maxFontSize: 8,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								      style: styleTextHome,
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  Widget buildEmptyWidget() {
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    return Directionality(
							 | 
						||
| 
								 | 
							
								      textDirection: ui.TextDirection.ltr,
							 | 
						||
| 
								 | 
							
								      child: Row(
							 | 
						||
| 
								 | 
							
								        mainAxisSize: MainAxisSize.min,
							 | 
						||
| 
								 | 
							
								        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
							 | 
						||
| 
								 | 
							
								        crossAxisAlignment: CrossAxisAlignment.start,
							 | 
						||
| 
								 | 
							
								        children: <Widget>[
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              getTimeDigit("00"),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.days.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								          buildSeparator(),
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              getTimeDigit("00"),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.hours.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								          buildSeparator(),
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              getTimeDigit("00"),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.minutes.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								          buildSeparator(),
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              getTimeDigit("00"),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.seconds.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								        ],
							 | 
						||
| 
								 | 
							
								      ),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  Widget buildCountdownTimer(CurrentRemainingTime? time) {
							 | 
						||
| 
								 | 
							
								    if (time == null) {
							 | 
						||
| 
								 | 
							
								      return buildEmptyWidget();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    return Directionality(
							 | 
						||
| 
								 | 
							
								      textDirection: ui.TextDirection.ltr,
							 | 
						||
| 
								 | 
							
								      child: Row(
							 | 
						||
| 
								 | 
							
								        mainAxisSize: MainAxisSize.min,
							 | 
						||
| 
								 | 
							
								        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
							 | 
						||
| 
								 | 
							
								        crossAxisAlignment: CrossAxisAlignment.start,
							 | 
						||
| 
								 | 
							
								        children: <Widget>[
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              time.days == null ? getTimeDigit("00") : getTimeDigit(time.days! < 10 ? "0${time.days.toString()}" : time.days.toString()),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.days.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								          buildSeparator(),
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              time.hours == null ? getTimeDigit("00") : getTimeDigit(time.hours! < 10 ? "0${time.hours.toString()}" : time.hours.toString()),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.hours.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								          buildSeparator(),
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              time.min == null ? getTimeDigit("00") : getTimeDigit(time.min! < 10 ? "0${time.min.toString()}" : time.min.toString()),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.minutes.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								          buildSeparator(),
							 | 
						||
| 
								 | 
							
								          Column(
							 | 
						||
| 
								 | 
							
								            children: <Widget>[
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								              time.sec == null ? getTimeDigit("00") : getTimeDigit(time.sec! < 10 ? "0${time.sec.toString()}" : time.sec.toString()),
							 | 
						||
| 
								 | 
							
								              getTimeText(LocaleKeys.seconds.tr()),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								        ],
							 | 
						||
| 
								 | 
							
								      ),
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  @override
							 | 
						||
| 
								 | 
							
								  Widget build(BuildContext context) {
							 | 
						||
| 
								 | 
							
								    return CountdownTimer(
							 | 
						||
| 
								 | 
							
								      endTime: timeToMarathon,
							 | 
						||
| 
								 | 
							
								      onEnd: null,
							 | 
						||
| 
								 | 
							
								      widgetBuilder: (BuildContext context, CurrentRemainingTime? time) {
							 | 
						||
| 
								 | 
							
								        return buildCountdownTimer(time);
							 | 
						||
| 
								 | 
							
								      },
							 | 
						||
| 
								 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 |