hi am new to flutter, trying out navigation but I get
multiple heroes that share the same tag within a subtree error.
heres my code
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main()=> runApp(Entry());
class Entry extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter FireStore Demo',
home: MainFireClass(),
//initialRoute:'/main',
routes: <String, WidgetBuilder>{
'/first':(BuildContext context) => NavigatorOne() ,
'/second':(BuildContext context) => NavigatorTwo(),
'/third':(BuildContext context) => NavigatorThree(),
},
);
}
}
class MainFireClass extends StatefulWidget {
@override
_MainFireClassState createState() =>_MainFireClassState();
}
class _MainFireClassState extends State<MainFireClass> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(actions: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward_ios),
onPressed: (){
Navigator.of(context).pushNamed('/first');
},tooltip: "add",
),
],),
backgroundColor: Colors.greenAccent,
body: StreamBuilder(
stream: Firestore.instance.collection("flutter_data").snapshots(),
builder: (BuildContext context,AsyncSnapshot<QuerySnapshot> snapshot){
if(!snapshot.hasData) return CircularProgressIndicator();
return FirestoreListView(documents: snapshot.data.documents);
},
),
);
}
}
class FirestoreListView extends StatelessWidget {
final List<DocumentSnapshot> documents;
FirestoreListView({this.documents});
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: documents.length,
itemExtent: 90.0,
itemBuilder: (BuildContext context, int index){
var title = documents[index].data["jay"];
var updator = documents[index].data["b"];
var dmytext = "no marks";
return ListTile(
trailing: IconButton(icon: Icon(Icons.delete),color: Colors.red,onPressed: (){},),
title: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
border: Border.all(color: Colors.black),
),
child: Row(
children: <Widget>[
FloatingActionButton(
),
Expanded(
child:title == null?Text('wait ...Score $updator'): Text("$title and Score $updator"),
),
],
),
),
);
},
);
}
}
class NavigatorOne extends StatefulWidget {
@override
_NavigatorOneState createState() => _NavigatorOneState();
}
class _NavigatorOneState extends State<NavigatorOne> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
color: Colors.green,
child: RaisedButton(child: Text(' one 1'),onPressed: (){
Navigator.of(context).pushNamed('/second');
},),
),
);
}
}
class NavigatorTwo extends StatefulWidget {
@override
_NavigatorTwoState createState() => _NavigatorTwoState();
}
class _NavigatorTwoState extends State<NavigatorTwo> {
@override
Widget build(BuildContext context) {
return Scaffold(
body:Container(
color: Colors.redAccent,
child: RaisedButton(child: Text(' two 2'),onPressed: (){
Navigator.of(context).pushNamed('/third');
},
)
) ,
);
}
}
class NavigatorThree extends StatefulWidget {
@override
_NavigatorThreeState createState() => _NavigatorThreeState();
}
class _NavigatorThreeState extends State<NavigatorThree> {
@override
Widget build(BuildContext context) {
return Scaffold(
body:Container(
color: Colors.green,
child:RaisedButton(child: Text(' three 3'),onPressed: (){
},
)
) ,
);
}
}
when I ran this I get the following error and it gives me a dark screen, what am I doing wrong and how can I handle this
══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (21786): The following assertion was thrown during a scheduler callback:
I/flutter (21786): There are multiple heroes that share the same tag within a subtree.
I/flutter (21786): Within each subtree for which heroes are to be animated (typically a PageRoute subtree), each Hero
I/flutter (21786): must have a unique non-null tag.
I/flutter (21786): In this case, multiple heroes had the following tag: <default FloatingActionButton tag>
I/flutter (21786): Here is the subtree for one of the offending heroes:
I/flutter (21786): # Hero(tag: <default FloatingActionButton tag>, state: _HeroState#b99a6)
I/flutter (21786): # └KeyedSubtree-[GlobalKey#b5093]
I/flutter (21786): # └RawMaterialButton(state: _RawMaterialButtonState#821c0)
I/flutter (21786): # └Semantics(container: true, properties: SemanticsProperties, label: null, value: null, hint: null, renderObject: RenderSemanticsAnnotations#9781a relayoutBoundary=up4)