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.
		
		
		
		
		
			
		
			
				
					
					
						
							53 lines
						
					
					
						
							2.1 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							53 lines
						
					
					
						
							2.1 KiB
						
					
					
				
								import 'dart:async';
							 | 
						|
								
							 | 
						|
								import 'package:bloc/bloc.dart';
							 | 
						|
								import 'package:flutter/cupertino.dart';
							 | 
						|
								import 'package:go_router/go_router.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/constants/my_constants.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/routers/my_routes.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/utils/context_provider.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/core/utils/local_storage.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/intro/presentation/bloc/intro_event.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/intro/presentation/bloc/intro_state.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/intro/presentation/ui/screens/intro_1_screen.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/intro/presentation/ui/screens/intro_2_screen.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/intro/presentation/ui/screens/intro_3_screen.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/intro/presentation/ui/screens/intro_4_screen.dart';
							 | 
						|
								import 'package:hadi_hoda_flutter/features/intro/presentation/ui/screens/intro_5_screen.dart';
							 | 
						|
								
							 | 
						|
								class IntroBloc extends Bloc<IntroEvent, IntroState> {
							 | 
						|
								  /// ------------constructor------------
							 | 
						|
								  IntroBloc() : super(const IntroState()){
							 | 
						|
								    on<ChangeIntroEvent>(_changeIntroEvent);
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  /// ------------UseCases------------
							 | 
						|
								
							 | 
						|
								  /// ------------Variables------------
							 | 
						|
								  final List<Widget> intros = [
							 | 
						|
								    Intro1Screen(key: Key('0')),
							 | 
						|
								    Intro2Screen(key: Key('1')),
							 | 
						|
								    Intro3Screen(key: Key('2')),
							 | 
						|
								    Intro4Screen(key: Key('3')),
							 | 
						|
								    Intro5Screen(key: Key('4')),
							 | 
						|
								  ];
							 | 
						|
								
							 | 
						|
								  /// ------------Controllers------------
							 | 
						|
								
							 | 
						|
								  /// ------------Functions------------
							 | 
						|
								  Future<void> goToLevelPage() async {
							 | 
						|
								    await LocalStorage.saveData(key: MyConstants.firstIntro, value: 'true');
							 | 
						|
								    if (ContextProvider.context.mounted) {
							 | 
						|
								      ContextProvider.context.replaceNamed(Routes.levelPage);
							 | 
						|
								    }
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  /// ------------Api Calls------------
							 | 
						|
								  FutureOr<void> _changeIntroEvent(ChangeIntroEvent event, Emitter emit) async {
							 | 
						|
								    if (state.currentIntro < intros.length - 1) {
							 | 
						|
								      emit(state.copyWith(currentIntro: state.currentIntro + 1));
							 | 
						|
								    } else {
							 | 
						|
								      goToLevelPage();
							 | 
						|
								    }
							 | 
						|
								  }
							 | 
						|
								}
							 |