“类型'ActorSkin'不是类型转换中类型'ActorNode'的子类型”首次呈现时家庭小部件中的错误

时间:2019-07-10 04:24:47

标签: flutter

我在这里使用flare_flutter软件包1.5.3和bloc进行状态管理 基本上,家庭小部件所做的是使用流生成器和计时器每10.0秒更改一次在屏幕上播放的照明弹演员 仅当首次渲染窗口小部件并且开始闪光动画会意外地切换黑白动画(但是应该每10.0秒发生一次)时才发生错误,而不是经过一段时间(大约30秒钟的渲染时间)后才出现错误,并且一切正常。 />   //首页小部件     类Home扩展了StatelessWidget {

final String heroName="assets/flare/TheArchitect.flr";
final String name="TheRefactorer";
final String status="xxx";
// bool userName async(value,banner){
//   heroName=value;
//   status=banner;
//   return true;
//   }

  List drawer(){
  List<Widget> flareList=[];
  flareList.add(new DrawerHeader(
              child: Text('List of Heroes available'),
              decoration: BoxDecoration(
                color: Colors.pink,
              ),
            ),);
 List flareList1=_filesToWarmup;
 flareList1.remove(heroName);
 for(int i=0;i<flareList1.length;i++)
 {
   flareList.add(new ListTile(
     trailing: Icon(Icons.arrow_right),
     title:Text(flareList1[i].split("/")[2].split(".")[0]),
     onTap: (){
       print(flareList1[i]);
       },
     ));
 }
 return flareList;
  }
  Timer homeHeroTimer=null;
  Widget build(BuildContext  context){
    final bloc=Provider.of(context);
      double width = MediaQuery.of(context).size.width;
 double height = MediaQuery.of(context).size.height;

return Scaffold (

     appBar: AppBar(
       actions: <Widget>[
         GestureDetector(
           child: Icon(Icons.power_settings_new
           ),
           onTap: (){
             print("aaction for logout");
             homeHeroTimer.cancel();
             //bloc.disposeHomeTimer();
              Navigator.of(context).pushReplacementNamed('/login');
           },

         )
       ],
backgroundColor: Colors.pink,
     ),
   drawer:Drawer(
  child: ListView(
    children:drawer()
  ),
),
     body:Center(
      child: Container(
       padding: EdgeInsets.fromLTRB(10.0,25.0,10.0,5.0),
          child: StreamBuilder(
          stream: bloc.homeTimer,
          builder: (context,AsyncSnapshot<String> snapshot){
            if(homeHeroTimer==null)
            {
              homeHeroTimer=Timer(Duration(seconds: 10),(){
        print("10.0 seconds");

        bloc.updateInitHome("update");
    });  
            }
               if(! homeHeroTimer.isActive) {homeHeroTimer=Timer(Duration(seconds: 10),(){
        print("10.0 seconds");

        bloc.updateInitHome("update");
    });
               }
               else if(homeHeroTimer.isActive){
                 print("timer still running");
               }
        print(homeHeroTimer.isActive);
        var random=new Random();
   // print(snapshot.data);
    String currHeroName=_filesToWarmup[random.nextInt(_filesToWarmup.length)];


            return GestureDetector(
              child: AnimatedContainer(
                color: Colors.white,
                duration: Duration( seconds: 4),
                curve: Curves.easeIn,
                child: Stack(
       alignment: Alignment.center,
       overflow: Overflow.visible,
       children: <Widget>[
       Container(

color: Colors.black,

    ),
    Positioned(
      bottom: 0.0,
      child:Text(currHeroName.split("/")[2].split(".")[0],
     style:new TextStyle(color: Colors.white, fontSize: 20.0,fontWeight:FontWeight.bold,letterSpacing: 5.0 ) ,
     ),
    ),
     Positioned(
       bottom: 50.0,
       width: width/2+100.0,
       height: height/2+245.0,
       child:new FlareActor(currHeroName, fit:BoxFit.fill, animation:"idle"),
     ),

       ],
     ),

              ),
     onDoubleTap: (){
             print("doubletapped========================================================================");
                  homeHeroTimer.cancel();
                  bloc.updateInitHome("update");

                    print(homeHeroTimer.toString());
           },
            );
          },
        ),


      ),
     ), 
);



  }
}


//Bloc file
class Bloc extends Object with Validator{
  final _email=BehaviorSubject<String>();
  final _password=BehaviorSubject<String>();
  final _timeer=BehaviorSubject<String>();
  final _homeTimer=BehaviorSubject<String>();
  Stream<String> get email=>_email.stream.transform(validateEmail);
  Stream<String> get password=>_password.stream.transform(validatePassword);
  Stream<String> get timeer=>_timeer.stream.transform(validateTimer);
    Stream<String> get homeTimer=>_homeTimer.stream.transform(validateHomeTimer);
  Stream<bool> get submitStream=> Observable.combineLatest2(email,password,(e,p)=>true);
  Function(String) get changeEmail=>_email.sink.add;
  Function(String) get changePassword=>_password.sink.add;
   Function(String) get updateInit=>_timeer.sink.add;
    Function(String) get updateInitHome=>_homeTimer.sink.add;
  String submitty(){
    String username=_email.value;
    String pass=_password.value;
    String val="email is $username and password is $pass ";
    print(val);
    return val;
  }
  dispose(){
    _email.close();
    _password.close();
  }
disposeTimer(){
_timeer.close();
}
disposeHomeTimer(){
_homeTimer.close();
}
}
class Validator {

final validateTimer=StreamTransformer<String,String>.fromHandlers(
  handleData:(timer,sink){
if(timer=="update")
{
  sink.add(timer);
}
else{
  sink.close();
}

  }
); 
final validateHomeTimer=StreamTransformer<String,String>.fromHandlers(
  handleData:(timer,sink){
if(timer=="update")
{
  sink.add(timer);
}
else{
  sink.close();
}

  }
);

0 个答案:

没有答案