在 MaterialApp 的应用栏中创建带有图标的简单英雄动画时,英雄动画似乎不使用主题颜色,除非在图标本身中明确指定了颜色。有人可以解释为什么未明确设置图标颜色时图标的颜色在飞行过程中会发生变化吗?英雄无权访问主题数据吗?或者它是否使用其他颜色集?
例子:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Hero(
tag: "mytag",
child: Material(
color: Colors.transparent,
child: IconButton(
icon: Icon(
Icons.menu,
// uncomment below line and the flying icon is white as expected...
// color: Theme.of(context).primaryIconTheme.color
),
onPressed: () {
Navigator.of(context).push(
PageRouteBuilder(
pageBuilder:
(context, animation, secondaryAnimation) => SecondPage()
)
);
},
),
),
),
),
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: <Widget> [
Hero(
tag: "mytag",
child: Material(
color: Colors.transparent,
child: IconButton(
icon: Icon(
Icons.menu,
// uncomment below line and the reverse flying icon is white as expected...
// color: Theme.of(context).primaryIconTheme.color
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
),
]
),
);
}
}