BlocProvider.of <AuthhBloc>上下文.addShowHome未触发任何事件

问题描述

我已经使用VS代码上的可用扩展名创建了集团。我也尝试通过按钮触发事件,但是不起作用。它显示调试控制台中的认状态和第一状态,即-“ AuthInitail”。每当我尝试触发任何新事件时,它都会显示相同的内容。我在下面提到代码-

auth_bloc.dart

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:Flutter/cupertino.dart';
part 'auth_event.dart';
part 'auth_state.dart';

class AuthBloc extends Bloc<AuthEvent,AuthState> {
  AuthBloc() : super(AuthInitial());

  @override
  Stream<AuthState> mapEventToState(
    AuthEvent event,) async* {
    if(event is AppInit){
      yield AppStarting();
      startTime();
    }
    if(event is ShowHome){
      yield HomeState();
    }
    if(event is ShowAuth){
      yield AuthInitial();
    }
    if(event is ShowRegsiter){
      yield RegsiterInit();
    }
  }


  startTime() async {
    var _duration = new Duration(seconds: 3);
    return new Timer(_duration,navigationPage);
  }

  void navigationPage() {
    this.add(ShowHome());
  }
}

auth_event.dart


abstract class AuthEvent extends Equatable {
  const AuthEvent();

  @override
  List<Object> get props => [];
}
  class AppInit extends AuthEvent{}

  class ShowRegsiter extends AuthEvent{}

  class ShowAuth extends AuthEvent{}

  class ShowHome extends AuthEvent{}

auth_state.dart


abstract class AuthState extends Equatable {
  const AuthState();
  @override
  List<Object> get props => [];
}

class AppStarting extends AuthState{}

class AuthInitial extends AuthState {}

class AuthLoading extends AuthState{}

class AuthSuccess extends AuthState{
  final String message;
  AuthSuccess({@required this.message}):super();
}

class AuthError extends AuthState{
  final String message;
  AuthError({@required this.message}):super();
}
class HomeState extends AuthState{}

class LoggedIn extends AuthState{}

class NotLoggedIn extends AuthState{}

class RegsiterInit extends AuthState{}

class RegisterLoading extends AuthState{}

class RegsiterSuccess extends AuthState{
  final String message;
  RegsiterSuccess({@required this.message}):super();
}

class RegisterError extends AuthState{
  final String message;
  RegisterError({@required this.message}):super();
}

main.dart

import 'package:ecommerce/src/Auth/otp.dart';
import 'package:ecommerce/src/Auth/password.dart';
import 'package:ecommerce/src/Auth/signup.dart';
import 'package:ecommerce/src/ui/CartPage.dart';
import 'package:ecommerce/src/ui/homePage.dart';
import 'package:ecommerce/src/Auth/login.Dart';
import 'package:ecommerce/src/splash/splash_screens.dart';
import 'package:ecommerce/src/Constant/Constant.dart';
import 'package:Flutter/material.dart';
import 'package:ecommerce/src/ui/profile.dart';
import 'package:Flutter_bloc/Flutter_bloc.dart';


void main(){
  final BlocProvider<AuthBloc> blocProvider = BlocProvider<AuthBloc>(
    create: (BuildContext cantext)=>AuthBloc(),child: MyApp(),);
  runApp(blocProvider);
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,title: 'Demo',theme: ThemeData(
        fontFamily: 'Open',primaryColor: Colors.orange,accentColor: Colors.orange,),routes: <String,WidgetBuilder>{
        SPLASH_SCREEN: (BuildContext context)=> AnimatedSplashScreen(),LOGIN_PAGE:(BuildContext context) => LoginPage(),OTP_PAGE:(BuildContext context)=> OTPPage(),PASSWORD_PAGE:(BuildContext context)=>LoginPWDPage(),SIGNUP_PAGE:(BuildContext context)=>SignupPage(),HOME_SCREEN: (BuildContext context)=> HomePage(),PROFILE_PAGE:(BuildContext context)=>ProfilePage(),CART_PAGE:(BuildContext context)=>CartPage()
      },home: BlocBuilder<AuthBloc,AuthState>(
        cubit: AuthBloc(),builder: (_,state){
          print(state.toString());
          if(state is AuthInitial){
            // return HomePage();
            return AnimatedSplashScreen(bloc: BlocProvider.of<AuthBloc>(context));
          }
          if(state is HomeState){
            return HomePage();
          }
          return CircularProgressIndicator();
        },)
    );
  }
}

问题- 我创建了一个函数startTime()来在3节之后触发一个事件,但是它不起作用。请帮我弄清楚

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)