Bottomnavigatorbar is not accepting pages. How to fix?

Asked

Viewed 55 times

-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.

Aqui está o Erro

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'),
          ],
        ),
      ),
    );
  }
}
  • 1

    What is the code of PendentesPage() error can be there, there is no parameter in the constructor?

  • Update with the Pendentespage code()

  • Strange this code compile without parameter title, try: PendentesPage(title: 'Título da Página'),

  • I solved the problem, so I had to change the type the extends to Statelesswidget

1 answer

0

This error is related to the "Text()" Widget, it is occurring because you did not initialize the "widget.title" parameter that is being passed to your "_Myhomepagestate" class through the constructor. You are using it in this class without first initializing it with a value, and where to use 'Myhomepage()' or 'Pendentespage()', declare them as follows: NameClass(title: 'meu titulo'). I think this will solve

  • This error informs you that the required parameter in the "Text()" widget, which is a String in your declaration, is null, which is not allowed, and if you do not start the value of "widget.title", which is being used in one of the "Text(widget.title)"it will be called null when used, thus causing the error in question. I hope you understood kkkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.