Created
March 24, 2019 03:10
-
-
Save mono0926/1c3237c3259c07b43a2d157d0c27d71a 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:animations/widget/app_scaffold.dart'; | |
import 'package:flutter/material.dart'; | |
class AnimatedSwitcher2Page extends StatefulWidget { | |
static const routeName = 'AnimatedSwitcher2Page'; | |
@override | |
_AnimatedSwitcher2PageState createState() => _AnimatedSwitcher2PageState(); | |
} | |
class _AnimatedSwitcher2PageState extends State<AnimatedSwitcher2Page> { | |
static const _texts = [ | |
'First', | |
'Second', | |
'Third', | |
]; | |
static const _colors = [ | |
Colors.black, | |
Colors.blue, | |
Colors.red, | |
]; | |
var _index = 0; | |
String get _currentText => _texts[_index % 3]; | |
Color get _currentColor => _colors[_index % 3]; | |
@override | |
Widget build(BuildContext context) { | |
return AppScaffold( | |
title: 'AnimatedSwitcher', | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_index++; | |
}); | |
}, | |
child: const Icon(Icons.refresh), | |
), | |
child: Center( | |
child: AnimatedSwitcher( | |
duration: const Duration(milliseconds: 1000), | |
transitionBuilder: (child, animation) { | |
return FadeTransition( | |
opacity: animation.drive(CurveTween(curve: Interval(0.5, 1))), | |
child: child, | |
); | |
}, | |
child: Text(_currentText, | |
key: ValueKey(_currentText), | |
style: Theme.of(context) | |
.textTheme | |
.title | |
.copyWith(color: _currentColor)), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment