Home > Back-end >  Flutter Error: Too many positional arguments: 0 expected, but 1 found
Flutter Error: Too many positional arguments: 0 expected, but 1 found

Time:05-02

I am trying to create a bottom navigation bar for a flutter website. I'm getting an error which is mainly having too many positional arguments. The error is coming from my BottomBar class. I get the error when I call the BottomBar constructor. Please may someone kindly assist

class BottomBar extends StatelessWidget {
  const BottomBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
}

I call the constructor BottomBar() then get the error

This is the error:

Too many positional arguments: 0 expected, but 1 found.
Try removing the extra positional arguments, or specifying the name for named arguments.

CodePudding user response:

There is no problem with your class!

import 'package:flutter/material.dart';

class BottomBar extends StatelessWidget {
  const BottomBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
}}

CodePudding user response:

When you call BottomBar() you are trying to pass a parameter but your BottomBar() class doesn't have any parameter it just have one optional parameter. So you must call it like: BottomBar();

And you will be fine.

  • Related