-2
I’m trying to make an app that uses Bottomnavigatorbar as a tool to navigate between screens, but by placing a page to be executed after clicking on one of the menu icons, it’s returning a string error.
Here is the revealing code to resolve the error The error is in _widgetOptions, where I call one of my created screens.
import 'package:app_work/telas/pendentes.dart';
import 'package:flutter/material.dart';
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
List<Widget> _widgetOptions = <Widget>[
Text('Bom Dia'),
PendentesPage(),
Text('Boa noite')
];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text(widget.title),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Página Inicial'),
),
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Pendentes'),
),
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Concluídas'),
)
],
selectedItemColor: Colors.blue,
onTap: (index){
setState(() {
_selectedIndex = index;
});
},
),
body: _widgetOptions.elementAt(_selectedIndex),
);
}
}
Pendentespage Code()
import 'package:flutter/material.dart';
class PendentesPage extends StatefulWidget {
PendentesPage({Key key, this.title}) : super(key: key);
final String title;
@override
_PendentesPageState createState() => _PendentesPageState();
}
class _PendentesPageState extends State<PendentesPage> {
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.lightBlue,
appBar: AppBar(
backgroundColor: Colors.yellow,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('TESTANDO'),
],
),
),
);
}
}
What is the code of
PendentesPage()
error can be there, there is no parameter in the constructor?– rubStackOverflow
Update with the Pendentespage code()
– Bruno Gomes
Strange this code compile without parameter
title
, try:PendentesPage(title: 'Título da Página'),
– rubStackOverflow
I solved the problem, so I had to change the type the extends to Statelesswidget
– Bruno Gomes