Created
February 3, 2025 00:47
-
-
Save diegoveloper/ccd8cc31e9afe44688d6df781c4dc075 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class TestFlutter2 extends StatefulWidget { | |
const TestFlutter2({super.key}); | |
@override | |
TestFlutter2State createState() => TestFlutter2State(); | |
} | |
class TestFlutter2State extends State<TestFlutter2> { | |
bool _isActive = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
// Problema: Ya conocemos la función del AnimatedSwitcher, ahora queremos hacer una animación, con el mismo AnimatedSwitcher | |
// Actualizar el código para que anime 2 Container uno azul y uno rojo con la transación que provee el AnimatedSwitcher | |
AnimatedSwitcher( | |
duration: const Duration(seconds: 1), | |
child: _isActive | |
? Container( | |
color: Colors.red, | |
height: 200, | |
width: 200, | |
alignment: Alignment.center, | |
) | |
: const FlutterLogo( | |
size: 200, | |
), | |
), | |
const SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: () { | |
setState(() { | |
_isActive = !_isActive; | |
}); | |
}, | |
child: const Text("Play"), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment