mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
next_gen_ui_demo: Dispose of old AnimationControllers (#1852)
This commit is contained in:
@@ -74,7 +74,17 @@ List<
|
|||||||
typedef ColorCallback = void Function(Color colorSchemeSeed);
|
typedef ColorCallback = void Function(Color colorSchemeSeed);
|
||||||
|
|
||||||
class _NextGenAppState extends State<NextGenApp> {
|
class _NextGenAppState extends State<NextGenApp> {
|
||||||
int step = 0;
|
int _step = 0;
|
||||||
|
int get step => _step;
|
||||||
|
set step(int i) {
|
||||||
|
_step = switch (i) {
|
||||||
|
(int a) when a < 0 => 0,
|
||||||
|
(int a) when a >= steps.length => steps.length - 1,
|
||||||
|
_ => i,
|
||||||
|
};
|
||||||
|
debugPrint('Step ${step + 1} of ${steps.length}');
|
||||||
|
}
|
||||||
|
|
||||||
Color? colorSchemeSeed;
|
Color? colorSchemeSeed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -107,8 +117,7 @@ class _NextGenAppState extends State<NextGenApp> {
|
|||||||
child: const Icon(Icons.arrow_back),
|
child: const Icon(Icons.arrow_back),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (step > 0) step--;
|
step--;
|
||||||
debugPrint('Step = $step');
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -123,8 +132,7 @@ class _NextGenAppState extends State<NextGenApp> {
|
|||||||
child: const Icon(Icons.arrow_forward),
|
child: const Icon(Icons.arrow_forward),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (step + 1 < steps.length) step++;
|
step++;
|
||||||
debugPrint('Step = $step');
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -140,7 +148,6 @@ class _NextGenAppState extends State<NextGenApp> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
step = 0;
|
step = 0;
|
||||||
debugPrint('Step = $step');
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -255,7 +255,15 @@ class _StartBtnState extends State<_StartBtn> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.animate(autoPlay: false, onInit: (c) => _btnAnim = c)
|
.animate(
|
||||||
|
autoPlay: false,
|
||||||
|
onInit: (c) {
|
||||||
|
if (_btnAnim != null && _btnAnim != c) {
|
||||||
|
_btnAnim?.dispose();
|
||||||
|
}
|
||||||
|
_btnAnim = c;
|
||||||
|
},
|
||||||
|
)
|
||||||
.shimmer(duration: .7.seconds, color: Colors.black),
|
.shimmer(duration: .7.seconds, color: Colors.black),
|
||||||
)
|
)
|
||||||
.animate()
|
.animate()
|
||||||
|
|||||||
@@ -261,7 +261,15 @@ class _StartBtnState extends State<_StartBtn> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.animate(autoPlay: false, onInit: (c) => _btnAnim = c)
|
.animate(
|
||||||
|
autoPlay: false,
|
||||||
|
onInit: (c) {
|
||||||
|
if (_btnAnim != null && _btnAnim != c) {
|
||||||
|
_btnAnim?.dispose();
|
||||||
|
}
|
||||||
|
_btnAnim = c;
|
||||||
|
},
|
||||||
|
)
|
||||||
.shimmer(duration: .7.seconds, color: Colors.black),
|
.shimmer(duration: .7.seconds, color: Colors.black),
|
||||||
)
|
)
|
||||||
.animate()
|
.animate()
|
||||||
|
|||||||
@@ -261,7 +261,15 @@ class _StartBtnState extends State<_StartBtn> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.animate(autoPlay: false, onInit: (c) => _btnAnim = c)
|
.animate(
|
||||||
|
autoPlay: false,
|
||||||
|
onInit: (c) {
|
||||||
|
if (_btnAnim != null && _btnAnim != c) {
|
||||||
|
_btnAnim?.dispose();
|
||||||
|
}
|
||||||
|
_btnAnim = c;
|
||||||
|
},
|
||||||
|
)
|
||||||
.shimmer(duration: .7.seconds, color: Colors.black),
|
.shimmer(duration: .7.seconds, color: Colors.black),
|
||||||
)
|
)
|
||||||
.animate()
|
.animate()
|
||||||
|
|||||||
@@ -287,7 +287,15 @@ class _StartBtnState extends State<_StartBtn> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.animate(autoPlay: false, onInit: (c) => _btnAnim = c)
|
.animate(
|
||||||
|
autoPlay: false,
|
||||||
|
onInit: (c) {
|
||||||
|
if (_btnAnim != null && _btnAnim != c) {
|
||||||
|
_btnAnim?.dispose();
|
||||||
|
}
|
||||||
|
_btnAnim = c;
|
||||||
|
},
|
||||||
|
)
|
||||||
.shimmer(duration: .7.seconds, color: Colors.black),
|
.shimmer(duration: .7.seconds, color: Colors.black),
|
||||||
)
|
)
|
||||||
.animate()
|
.animate()
|
||||||
|
|||||||
@@ -289,7 +289,15 @@ class _StartBtnState extends State<_StartBtn> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.animate(autoPlay: false, onInit: (c) => _btnAnim = c)
|
.animate(
|
||||||
|
autoPlay: false,
|
||||||
|
onInit: (c) {
|
||||||
|
if (_btnAnim != null && _btnAnim != c) {
|
||||||
|
_btnAnim?.dispose();
|
||||||
|
}
|
||||||
|
_btnAnim = c;
|
||||||
|
},
|
||||||
|
)
|
||||||
.shimmer(duration: .7.seconds, color: Colors.black),
|
.shimmer(duration: .7.seconds, color: Colors.black),
|
||||||
)
|
)
|
||||||
.animate()
|
.animate()
|
||||||
|
|||||||
@@ -289,7 +289,15 @@ class _StartBtnState extends State<_StartBtn> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.animate(autoPlay: false, onInit: (c) => _btnAnim = c)
|
.animate(
|
||||||
|
autoPlay: false,
|
||||||
|
onInit: (c) {
|
||||||
|
if (_btnAnim != null && _btnAnim != c) {
|
||||||
|
_btnAnim?.dispose();
|
||||||
|
}
|
||||||
|
_btnAnim = c;
|
||||||
|
},
|
||||||
|
)
|
||||||
.shimmer(duration: .7.seconds, color: Colors.black),
|
.shimmer(duration: .7.seconds, color: Colors.black),
|
||||||
)
|
)
|
||||||
.animate()
|
.animate()
|
||||||
|
|||||||
Reference in New Issue
Block a user