大家好
希望你没事,我需要你的帮助,我收到此错误每次我导航到另一个页面时,子树中有多个英雄共享相同的标签
在 MyIdemDetailsScreen 上我调用我的应用程序栏,
class _MyItemDetailsScreenState extends State<MyItemDetailsScreen> {
// ignore: prefer_typing_uninitialized_variables
final GlobalKey<FormState> _forKey = GlobalKey<FormState>();
TextEditingController counterTextEditingController = TextEditingController();
forValidation() {
if (counterTextEditingController.text.isNotEmpty) {
int itemCounter = int.parse(counterTextEditingController.text);
List<String> separateItemIDsList = separateItemIDs();
//1.check if item exist already in cart
separateItemIDsList.contains(widget.model!.itemID)
? Fluttertoast.showToast(msg: "Item is already in Cart.")
:
//2.add to cart
addItemToCart(widget.model!.itemID, context, itemCounter);
} else {
showDialog(
context: context,
builder: (c) {
return ErrorDialog(
message: "Metter une valeur",
);
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: const MyAppBar(),// i call my appbar here
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: InkWell(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(8.0),
topRight: Radius.circular(8.0),
),
child: Image.network(
widget.model!.thumbnailUrl.toString(),
height: 290,
fit: BoxFit.fill),
),
ListTile(
title: Text(
textAlign: TextAlign.left,
widget.model!.title.toString().toUpperCase(),
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 20),
),
subtitle: Text(
textAlign: TextAlign.left,
widget.model!.shortInfo.toString(),
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 20)))
],
),
),
),
),
Padding(
padding: const EdgeInsets.all(18.0),
child: Form(
key: _forKey,
child: Column(
children: [
TextFormField(
decoration:
const InputDecoration(labelText: "Enter your number"),
keyboardType: TextInputType.number,
controller: counterTextEditingController,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp("[0-9]"),
),
],
),
],
)),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
widget.model!.longDescription.toString(),
textAlign: TextAlign.justify,
style:
const TextStyle(fontWeight: FontWeight.normal, fontSize: 14),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"${widget.model!.price} CDF",
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
),
const SizedBox(
height: 10,
),
Center(
child: InkWell(
onTap: () {
forValidation();
},
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.cyan,
Colors.amber,
],
begin: FractionalOffset(0.0, 0.0),
end: FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp,
)),
width: MediaQuery.of(context).size.width - 13,
height: 50,
child: const Center(
child: Text(
"Add to Cart",
style: TextStyle(color: Colors.white, fontSize: 15),
),
),
),
),
),
],
),
);
}
}
这是我的应用栏的代码
class _MyAppBarState extends State<MyAppBar> {
@override
Widget build(BuildContext context) {
return AppBar(
flexibleSpace: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.cyan,
Colors.amber,
],
begin: FractionalOffset(0.0, 0.0),
end: FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp,
)),
),
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(Icons.keyboard_backspace_outlined)),
title: const Text(
"iFood",
style: TextStyle(
fontSize: 45, fontFamily: "Signatra", color: Colors.white),
),
centerTitle: true,
automaticallyImplyLeading: true,
actions: [
Stack(
children: [
IconButton(
icon: const Icon(
Icons.shopping_cart,
color: Colors.cyan,
),
onPressed: () {
//send user to cart screen
Navigator.push(
context,
MaterialPageRoute(
builder: (c) => CartItem(ifoodUID: widget.ifoodUID)));
},
),
Positioned(
child: Stack(
children: [
const Icon(
Icons.brightness_1,
size: 20.0,
color: Colors.green,
),
Positioned(
top: 3,
right: 4,
child: Center(
child: Consumer<CartItemCounter>(
builder: (context, counter, c) {
return Text(
counter.count.toString(),
style: const TextStyle(
color: Colors.white, fontSize: 12),
);
},
),
),
),
],
),
),
],
),
],
);
}
}
我调用 CartItem 页面
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
flexibleSpace: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.cyan,
Colors.amber,
],
begin: FractionalOffset(0.0, 0.0),
end: FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp,
)),
),
leading: IconButton(
icon: const Icon(Icons.clear_all),
onPressed: () {
clearCartNow(context);
},
),
title: const Text(
"iFood",
style: TextStyle(fontSize: 45, fontFamily: "Signatra"),
),
centerTitle: true,
automaticallyImplyLeading: true,
actions: [
Stack(
children: [
IconButton(
icon: const Icon(
Icons.shopping_cart,
color: Colors.cyan,
),
onPressed: () {
print("clicked");
},
),
Positioned(
child: Stack(
children: [
const Icon(
Icons.brightness_1,
size: 20.0,
color: Colors.green,
),
Positioned(
top: 3,
right: 4,
child: Center(
// child: Consumer<CartItemCounter>(
// builder: (context, counter, c)
// {
// return Text(
// counter.count.toString(),
// style: const TextStyle(color: Colors.white, fontSize: 12),
// );
// },
// ),
),
),
],
),
),
],
),
],
),
floatingActionButton: Center(
child: Stack(
children: [
RadialMenu(
centerButtonAlignment: Alignment
.bottomCenter, // by default alignment is set to Alignment.center
centerButtonSize: 0.5, // size ranging from 0.0 to 1.0
children: [
RadialButton(
icon: const Icon(Icons.navigate_next),
buttonColor: Colors.teal,
onPress: () {
clearCartNow(context);
// Navigator.push(context, MaterialPageRoute(builder: (c)=> const MySplashScreen()));
Fluttertoast.showToast(msg: "Cart has been cleared.");
}),
RadialButton(
icon: const Icon(Icons.clear_all),
buttonColor: Colors.green,
onPress: () {}),
/* you can add any number of buttons, although it's
not recommended to insert beyond 8-9 buttons. */
],
),
],
)),
body: const Center());
}
我总是遇到这个异常,请你帮助我,我想了好几天这个表达方式,但我无法解决它,
Floating Action Button
(FAB)。
为每个 FAB 提供唯一的英雄标签。
FloatinActionButton(
heroTag: 'anyTag',
...
)