Home > Software engineering >  fade in only animation in flutter
fade in only animation in flutter

Time:01-25

I have a home screen and I want to apply fade in animation in image and text I have a image in center and then two line of text and I just want them to fade in for the one time only I have gone through some various examples but they all contains fade in and fade out i just want to reveal thosse image and text to user and the pause.

CodePudding user response:

Try with this it will fade in from initState also i delayed 1 second you can modify it.

bool _visible = false;
 @override
  void initState() {
    
    Future.delayed(const Duration(seconds: 1), () {
    setState(() {
            _visible = !_visible;
          }); 
    });
     
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: AnimatedOpacity(
          // If the widget is visible, animate to 0.0 (invisible).
          // If the widget is hidden, animate to 1.0 (fully visible).
          opacity: _visible ? 1.0 : 0.0,
          duration: const Duration(milliseconds: 500),
          // The green box must be a child of the AnimatedOpacity widget.
          child:Column(
          children:[
          Image.network("https://cdn0.iconfinder.com/data/icons/business-startup-10/50/5-256.png")
          ,
          const Text("Your text")
          ])
        ),
      ),
     
    );
  }
  •  Tags:  
  • Related