颤振英雄小部件在进入新页面时不工作



我目前正在使用的英雄小部件的扑动。我的问题是,英雄只有在我从个人资料屏幕切换到聊天屏幕时才有效,而不是从聊天屏幕切换到个人资料屏幕。标签是一样的,但我就是不明白为什么它不工作。对于所有输入

聊天界面

class _AppBarTitle extends StatelessWidget {
const _AppBarTitle({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final channel = StreamChannel.of(context).channel;
return Row(
children: [
Hero(
tag: 'community-profile-picture',
child: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Avatar.medium(
url: Helpers.randomPictureUrl(), // can be a random image url
onTap: () {
Navigator.of(context).push(
PersonalDevelopmentProfileScreen.routeWithChannel(
channel));
}),
),
),
const SizedBox(
width: 16,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
Helpers.getChannelName(channel, context.currentUser!),
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 2),
],
)),
Padding(
padding: const EdgeInsets.all(8),
child: IconBackground(
icon: CupertinoIcons.info_circle,
onTap: () => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Center(
child: Text(
'About ${Helpers.getChannelName(channel, context.currentUser!)}'),
),
content: Text(
'${Helpers.getChannelName(channel, context.currentUser!)} Description'),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
primary: AppColors.accent),
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK',
style: TextStyle(color: AppColors.secondary)),
),
],
),
),
))
],
);
}
}

聊天屏幕支架

return Scaffold(
appBar: AppBar(
leadingWidth: 54,
leading: Align(
alignment: Alignment.centerRight,
child: IconBackground(
icon: CupertinoIcons.chevron_back,
onTap: () => Navigator.of(context).push(CustomPageRoute(
child: const HomeScreen(), direction: AxisDirection.right)),
),
),
title: const _AppBarTitle(),
),

配置屏幕

class _AppBarTitle extends StatelessWidget {
const _AppBarTitle({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Members Of Community',
style: GoogleFonts.lato(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black)),
const SizedBox(height: 2),
],
)),
const SizedBox(
width: 16,
),
Hero(
tag: 'community-profile-picture',
child: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Avatar.medium(
url: Helpers.randomPictureUrl(), // can be a random image url
onTap: () => Navigator.of(context).pop()),
),
),
],
);
}
}

配置文件屏幕支架

return Scaffold(
appBar: AppBar(
leadingWidth: 54,
leading: Align(
alignment: Alignment.centerRight,
child: IconBackground(
icon: CupertinoIcons.chevron_back,
onTap: () => Navigator.of(context).pop()),
),
title: const _AppBarTitle(),
),

《阿凡达》

class Avatar extends StatelessWidget {
const Avatar({
Key? key,
this.url,
required this.radius,
this.onTap,
}) : super(key: key);
const Avatar.small({
Key? key,
this.url,
this.onTap,
})  : radius = 18,
super(key: key);
const Avatar.medium({
Key? key,
this.url,
this.onTap,
})  : radius = 26,
super(key: key);
const Avatar.large({
Key? key,
this.url,
this.onTap,
})  : radius = 34,
super(key: key);
final double radius;
final String? url;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: _avatar(context),
);
}
Widget _avatar(BuildContext context) {
if (url != null) {
return CircleAvatar(
radius: radius,
backgroundImage: CachedNetworkImageProvider(url!),
backgroundColor: Theme.of(context).cardColor,
);
} else {
return CircleAvatar(
radius: radius,
backgroundColor: Theme.of(context).cardColor,
child: Center(
child: Text(
'?',
style: TextStyle(fontSize: radius),
),
),
);
}
}
}

在第二个小部件上提供hero顶层并遵循此模式,

聊天界面


class _AppBarTitle extends StatelessWidget {
const _AppBarTitle({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: row(context),
),
);
}
Row row(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Hero(
tag: 'community-profile-picture',
child: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _2AppBarTitle(),
),
);
},
child: Material(
child: Container(
height: 100,
width: 100,
color: Colors.green,
child: Text("tap")),
),
),
),
),
],
);
}
}

配置屏幕

class _2AppBarTitle extends StatelessWidget {
const _2AppBarTitle({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Hero(
tag: 'community-profile-picture',
child: Scaffold(
body: Padding(
padding: const EdgeInsets.only(bottom: 4),
child: GestureDetector(
onTap: () => Navigator.of(context).pop(),
child: Text("pop"),
),
),
),
);
}
}

最新更新