Смена цвета с анимацией
Можно ли сделать смену цвета нижнего бара с анимацией наподобие как анимация AnimatedSwithcer. Сделал так, но так как в ColorTween нужно указывать начальный и конечный цвет не получается сделать переход.
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
AnimationController animationController;
_MyHomePageState({this.animationController});
@override
void initState() {
animationController = AnimationController(
duration: const Duration(milliseconds: 500), vsync: this);
BlocProvider.of<BottomNavigationBloc>(context)
.colorTween
.animate(animationController);
super.initState();
}
@override
void dispose() {
super.dispose();
animationController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(50.0),
child: AppBar(),
),
body: BlocBuilder<BottomNavigationBloc, BottomNavigationState>(
builder: (context, state) {
if (state is Page1Loaded) {
return Page1();
}
if (state is Page2Loaded) {
return Page2();
}
if (state is Page3Loaded) {
return Page3();
}
return Container();
}),
bottomNavigationBar:
BlocBuilder<BottomNavigationBloc, BottomNavigationState>(
builder: (context, state) {
return AnimatedBuilder(
animation: animationController,
builder: (context, child) {
return BottomNavigationBar(
backgroundColor: BlocProvider.of<BottomNavigationBloc>(context)
.colorTween
.animate(animationController)
.value,
onTap: (index) async {
BlocProvider.of<BottomNavigationBloc>(context)
.add(OnTap(index: index));
if (animationController.status == AnimationStatus.completed) {
animationController.reset();
animationController.forward();
} else {
animationController.forward();
}
},
currentIndex:
BlocProvider.of<BottomNavigationBloc>(context).currentIndex,
type: BottomNavigationBarType.fixed,
items: [],
);
},
);
},
),
);
}
}