You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							119 lines
						
					
					
						
							4.2 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							119 lines
						
					
					
						
							4.2 KiB
						
					
					
				
								import 'package:flutter/material.dart';
							 | 
						|
								import 'package:flutter_bloc/flutter_bloc.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/common_ui/resources/my_assets.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/common_ui/resources/my_colors.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/common_ui/resources/my_text_style.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/status/base_status.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/utils/convert_size.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/utils/my_localization.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/utils/screen_size.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/widgets/error/error_state.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/download/presentation/bloc/download_bloc.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/download/presentation/bloc/download_event.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/download/presentation/bloc/download_state.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/download/presentation/ui/widgets/download_loading_widget.dart';
							 | 
						|
								
							 | 
						|
								class DownloadPage extends StatelessWidget {
							 | 
						|
								  const DownloadPage({super.key});
							 | 
						|
								
							 | 
						|
								  @override
							 | 
						|
								  Widget build(BuildContext context) {
							 | 
						|
								    return Scaffold(
							 | 
						|
								      body: Container(
							 | 
						|
								        height: context.heightScreen,
							 | 
						|
								        width: context.widthScreen,
							 | 
						|
								        decoration: BoxDecoration(
							 | 
						|
								          gradient: LinearGradient(
							 | 
						|
								            begin: Alignment.topCenter,
							 | 
						|
								            end: Alignment.bottomCenter,
							 | 
						|
								            colors: [
							 | 
						|
								              Color(0XFF00154C),
							 | 
						|
								              Color(0XFF150532),
							 | 
						|
								            ],
							 | 
						|
								          ),
							 | 
						|
								          image: DecorationImage(
							 | 
						|
								            image: AssetImage(MyAssets.pattern),
							 | 
						|
								            scale: 3,
							 | 
						|
								            repeat: ImageRepeat.repeat,
							 | 
						|
								            colorFilter: ColorFilter.mode(
							 | 
						|
								              Colors.white.withValues(alpha: 0.2),
							 | 
						|
								              BlendMode.srcIn,
							 | 
						|
								            ),
							 | 
						|
								          ),
							 | 
						|
								        ),
							 | 
						|
								        child: BlocBuilder<DownloadBloc, DownloadState>(
							 | 
						|
								            buildWhen: (previous, current) =>
							 | 
						|
								            previous.getFilesStatus != current.getFilesStatus,
							 | 
						|
								            builder: (context, state) {
							 | 
						|
								              if (state.getFilesStatus is BaseError) {
							 | 
						|
								                return Padding(
							 | 
						|
								                  padding: EdgeInsets.symmetric(
							 | 
						|
								                    vertical: MediaQuery.viewPaddingOf(context).bottom + MySpaces.s16,
							 | 
						|
								                    horizontal: 60,
							 | 
						|
								                  ),
							 | 
						|
								                  child: ErrorState(
							 | 
						|
								                    onTap: () => context.read<DownloadBloc>().add(GetImagesEvent()),
							 | 
						|
								                  ),
							 | 
						|
								                );
							 | 
						|
								              } else {
							 | 
						|
								                return Stack(
							 | 
						|
								                  alignment: Alignment.center,
							 | 
						|
								                  children: [
							 | 
						|
								                    _image(),
							 | 
						|
								                    _text(context),
							 | 
						|
								                    _loading(context),
							 | 
						|
								                  ],
							 | 
						|
								                );
							 | 
						|
								              }
							 | 
						|
								            }
							 | 
						|
								        ),
							 | 
						|
								      ),
							 | 
						|
								    );
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  MyImage _image() {
							 | 
						|
								    return MyImage(
							 | 
						|
								      image: MyAssets.hadiHoda,
							 | 
						|
								      size: 200,
							 | 
						|
								    );
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  Widget _text(BuildContext context) {
							 | 
						|
								    return PositionedDirectional(
							 | 
						|
								      bottom: 130,
							 | 
						|
								      child: Column(
							 | 
						|
								        spacing: MySpaces.s6,
							 | 
						|
								        children: [
							 | 
						|
								          Text(
							 | 
						|
								            context.translate.please_wait,
							 | 
						|
								            style: Marhey.medium22.copyWith(
							 | 
						|
								              color: MyColors.white,
							 | 
						|
								            ),
							 | 
						|
								          ),
							 | 
						|
								          StreamBuilder<DownloadEntity>(
							 | 
						|
								            initialData: DownloadEntity(),
							 | 
						|
								            stream: context.read<DownloadBloc>().loadingStream,
							 | 
						|
								             builder: (context, snapshot) => Text(
							 | 
						|
								              '${context.translate.downloading_data} (${snapshot.data?.count.toMB ?? 0.0}mb / ${snapshot.data?.total.toMB ?? 0.0}mb)',
							 | 
						|
								              style: Marhey.medium12.copyWith(
							 | 
						|
								                color: MyColors.white,
							 | 
						|
								              ),
							 | 
						|
								            ),
							 | 
						|
								          ),
							 | 
						|
								        ],
							 | 
						|
								      ),
							 | 
						|
								    );
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  Positioned _loading(BuildContext context) {
							 | 
						|
								    return Positioned(
							 | 
						|
								      bottom: MediaQuery.viewPaddingOf(context).bottom + MySpaces.s16,
							 | 
						|
								      child: DownloadLoadingWidget(
							 | 
						|
								        loadingStream: context.read<DownloadBloc>().loadingStream,
							 | 
						|
								      ),
							 | 
						|
								    );
							 | 
						|
								  }
							 | 
						|
								}
							 |