我的自定义应用程序栏在向后导航方面与 flutter stock AppBar 的行为不同。
有没有一种简单的方法可以为我的自定义应用栏提供此功能? ...涉及“自动暗示领先”吗?
仅供参考,如果你像我6岁一样向我解释,我不会生气;我对编码很陌生。 ..欢迎袜子木偶和代码片段。
我当前的代码(
gradient-app-bar.dart
&post_detail.dart
):
// MY CUSTOM APPBAR (GRADIENT-APP-BAR.DART) //
import 'package:flutter/material.dart';
class GradientAppBar extends StatelessWidget implements PreferredSizeWidget {
final double _preferredHeight = 200.0;
final String bizName;
final String streetAddress;
final String cityStateZip;
final String phoneNumber;
// final String bizHours;
final String masterList;
final Color gradientBegin, gradientEnd;
GradientAppBar({
this.bizName,
this.streetAddress,
this.cityStateZip,
this.phoneNumber,
// this.bizHours,
this.masterList,
this.gradientBegin,
this.gradientEnd,
// List<Widget> actions,
}):
assert(bizName != null),
assert(streetAddress != null),
assert(cityStateZip != null),
assert(phoneNumber != null),
// assert(bizHours != null),
assert(masterList != null),
assert(gradientBegin != null),
assert(gradientEnd != null);
@override
Widget build(BuildContext context) {
return Container(
height: _preferredHeight,
alignment: Alignment.center,
padding: EdgeInsets.only(top: 20.0),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: < Color > [
gradientBegin,
gradientEnd
]
)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(bizName,
style: TextStyle(
color: Colors.white,
letterSpacing: 5.0,
fontSize: 20.0,
fontWeight: FontWeight.w700
)
),
Text(streetAddress,
style: TextStyle(
color: Colors.white,
letterSpacing: 2.0,
fontSize: 16.0,
fontWeight: FontWeight.w500
)
),
Text(cityStateZip,
style: TextStyle(
color: Colors.white,
letterSpacing: 2.0,
fontSize: 16.0,
fontWeight: FontWeight.w500
)
),
Text(phoneNumber,
style: TextStyle(
color: Colors.white,
letterSpacing: 2.0,
fontSize: 16.0,
fontWeight: FontWeight.w500
)
),
// Text(bizHours,
// style: TextStyle(
// color:Colors.white,
// letterSpacing: 5.0,
// fontSize: 20.0,
// fontWeight: FontWeight.w700
// )
// ),
Text(masterList,
style: TextStyle(
color: Colors.white,
letterSpacing: 5.0,
fontSize: 20.0,
fontWeight: FontWeight.w700
)
),
],
),
);
}
@override
Size get preferredSize => Size.fromHeight(_preferredHeight);
}
// MY CUSTOM APPBAR IMPLEMENTED (POST_DETAIL.DART) //
import 'package:appvervemenu/gradient-app-bar.dart';
import 'package:appvervemenu/post_model.dart';
import 'package:flutter/material.dart';
class PostDetail extends StatelessWidget {
final Post post;
PostDetail({
@required this.post
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: GradientAppBar(
bizName: "BIZNAME",
streetAddress: "STREETADDRESS",
cityStateZip: "CITYSTATEZIP",
phoneNumber: "BIZPHONE",
masterList: "\n\nMASTERLIST",
gradientBegin: Color(0xFFB71C1C),
gradientEnd: Color(0xFFB71C1C),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
children: < Widget > [
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: < Widget > [
ListTile(
title: Text(post.title),
// subtitle: Text(post.title),
),
ListTile(
title: Text("Featuring"),
subtitle: Text(post.body),
),
ListTile(
// title: Text("ID"),
subtitle: Text("${post.id}"),
),
],
),
),
],
),
),
)
);
}
}
您可以使用以下代码根据父路由显示后退按钮:
(ModalRoute.of(context)?.impliesAppBarDismissal ?? false) ? BackButton() : null