【发布时间】:2020-06-14 08:12:18
【问题描述】:
我知道问题的根源,但我不知道如何解决。 当我单击转到另一个页面的按钮时,屏幕变黑了。
这里是调试控制台:
[38;5;248m════════ Exception caught by scheduler library ═════════════════════════════════[39;49m
There are multiple heroes that share the same tag within a subtree.
[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m
这是主页:
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Compilación de Flutter'),
),
body:Stack(children: <Widget>[
_fondoApp(),
_listView(context),
],) ,
floatingActionButton: Container(),
);
}
Widget _texto(){
return Text('Hola, bienvenido a mi compilacion de apps que yo mismo hice por un curso en flutter por internet.', style: TextStyle(
color: Colors.white, fontSize: 30
),);
}
Widget _fondoApp(){
return Container(
height: double.infinity,
width: double.infinity,
color: Color.fromRGBO(67, 107, 116, 1),
);
}
Widget _listView(BuildContext context){
return ListView(
padding: EdgeInsets.symmetric(horizontal: 10, vertical:15),
children: <Widget>[
_texto(),
SizedBox(height:20),
_targetadeApps(context, 'app1', Colors.green, "1", "primera", "una app contadora")
],);
}
Widget _targetadeApps(BuildContext context, String route, Color color, String no, String text, String description){
return Card(
child: Column(
children:<Widget>[
ListTile(
leading: Icon(Icons.check_circle_outline, color: color,),
title: Text("App $no", style: TextStyle(fontSize: 20.0,),),
subtitle: Text("Esta fue la $text app que cree trata sobre $description", style: TextStyle(fontSize: 18.0,),),
),
FlatButton(child: Text("Entrar", style: TextStyle(fontSize: 18.0,),), onPressed: (){
Navigator.pushNamed(context, route);
},)
]
),
);
}
}
这里是导航器需要去的页面
class ContadorPage extends StatefulWidget {
@override
createState() {
return _ContadorPageState();
}
}
class _ContadorPageState extends State<ContadorPage> {
final _estiloTexto=new TextStyle( fontSize: 27);
int _conteo = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AppContadora(app1)'),
centerTitle: true,
) ,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Contador:', style: _estiloTexto,),
Text('$_conteo', style: _estiloTexto),
],
) ,
),
floatingActionButton: _crearbotones()
);
}
Widget _crearbotones() {
return Stack(
children:<Widget>[ Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(width: 30.0,),
FloatingActionButton(
child: Icon(Icons.remove),
onPressed: () {
_sustraer();
},
),
Expanded(
child: SizedBox(),
),
FloatingActionButton(
child: Icon(Icons.exposure_zero),
onPressed: () {
_reset();
},
),
Expanded(
child: SizedBox(),
),
FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
_agregar();
},
)
],
),
]);
}
void _agregar(){
setState(() {
_conteo++;
});
}
void _sustraer(){
setState(() {
_conteo--;
});
}
void _reset(){
setState(() {
_conteo = _conteo -_conteo;
});
}
}
当我退出 2 个按钮时,导航器工作正常。 有人知道如何在不退出 2 个按钮的情况下使其工作吗?
【问题讨论】: