demo2.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'package:flutter/material.dart';
  2. class Demo3 extends StatefulWidget {
  3. const Demo3({Key? key}) : super(key: key);
  4. @override
  5. State<Demo3> createState() => _Demo3State();
  6. }
  7. class _Demo3State extends State<Demo3> with SingleTickerProviderStateMixin {
  8. late AnimationController _controller;
  9. late Animation _size;
  10. @override
  11. void initState() {
  12. _controller =
  13. AnimationController(duration: const Duration(seconds: 10), vsync: this);
  14. // ..addListener(() {
  15. // setState(() {});
  16. // });
  17. // _controller = AnimationController(vsync: this,duration: const Duration(seconds: 2));
  18. _controller.addListener(() {
  19. setState(() {
  20. });
  21. });
  22. _size = Tween(begin: 100.0, end: 200.0).animate(
  23. CurvedAnimation(parent: _controller, curve: const Interval(0.2, 0.23)));
  24. _controller.forward();
  25. super.initState();
  26. }
  27. @override
  28. void dispose() {
  29. _controller.dispose();
  30. super.dispose();
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. return Container(
  35. color: Colors.white,
  36. child: Column(
  37. crossAxisAlignment: CrossAxisAlignment.start,
  38. children: [
  39. Container(
  40. width: _size.value,
  41. height: _size.value,
  42. color: Colors.orange,
  43. )
  44. ],
  45. ),
  46. );
  47. }
  48. }