1 positional argument expected but 0 found. Try adding the missing argument

71 views Asked by At

This is Menu.dart and error is error row is which one is i had marked with stars it tells to add 1 more argument it writes that is expected. Also i added other pages. What i have to do for working GestureDetector.

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:salesapp/bread_model.dart';

    import 'breaddetails.dart';
    import 'breadspecial.dart';

    class menuPage extends StatefulWidget {
    const menuPage({super.key});

    @override
    State<menuPage> createState() => _menuPageState();
    }

    class _menuPageState extends State<menuPage> {
    //bread list
    List BreadList = [
    Bread(
        name: "Croissant",
        price: "5 dollars",
        imagePath: "images/croissant.png",
        rating: "5.0"),
    Bread(
        name: "Round Bread",
        price: "2 dollars",
        imagePath: "images/roundbread.png",
        rating: "4.0"),
    Bread(
        name: "Toast Bread",
        price: "1 dollar",
        imagePath: "images/toastbread.png",
        rating: "4.8"),
    Bread(
        name: "Butter Bread",
        price: "3 dollars",
        imagePath: "images/butterbread.png",
        rating: "4.2"),
    Bread(
        name: "Baguette",
        price: "12 dollars",
        imagePath: "images/baguette.png",
        rating: "5.0"),
    ];
    //define to details page
    void navigateToBreadDetails(int index) {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => breadDetails(
         ******************** bread: BreadList[index],
        ),
      ),
    );
    }

    @override
    Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[500],
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.transparent,
        leading: Icon(Icons.menu, color: Colors.orange),
        title: Text('Breads'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Container(
              decoration: BoxDecoration(
                  color: Colors.orange,
                  borderRadius: BorderRadius.circular(30)),
              margin: const EdgeInsets.symmetric(horizontal: 5),
              padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 18),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "BUTTERBREAD DISCOUNT 50%",
                        style:
                            GoogleFonts.abel(color: Colors.white, fontSize: 16),
                      ),
                      const SizedBox(height: 5),
                      Row(
                        children: [
                          //button
                          ElevatedButton(
                            style: ElevatedButton.styleFrom(
                                shape: BeveledRectangleBorder(
                                    borderRadius: BorderRadius.circular(5)),
                                backgroundColor: Colors.white),
                            onPressed: () {
                              Navigator.of(context).push(MaterialPageRoute(
                                  builder: (context) => menuPage()));
                            },
                            child: const Text(
                              "BUTTERBREAD",
                              style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 10,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                          const SizedBox(width: 5),
                          //image
                          Image.asset(
                            'images/butterbread.png',
                            height: 50,
                            width: 70,
                          ),
                        ],
                      ),
                    ],
                  )
                ],
              ),
            ),
          ),
          const SizedBox(height: 15),
          Padding(
            padding: EdgeInsets.symmetric(horizontal: 5),
            child: TextField(
              decoration: InputDecoration(
                  focusedBorder: OutlineInputBorder(
                    borderSide: const BorderSide(color: Colors.orange),
                    borderRadius: BorderRadius.circular(20),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: const BorderSide(color: Colors.orangeAccent),
                    borderRadius: BorderRadius.circular(20),
                  ),
                  hintText: "Search bar, you can use this.."),
            ),
          ),
          const SizedBox(height: 10),
          const Padding(
            padding: EdgeInsets.symmetric(horizontal: 5),
            child: Text(
              'TYPES OF BREAD',
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  color: Colors.orangeAccent,
                  fontSize: 20),
            ),
          ),
          const SizedBox(height: 3),
          Expanded(
              child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: BreadList.length,
            itemBuilder: (context, index) => breadSpe(
              bread: BreadList[index],
              onTap: () => navigateToBreadDetails(index),
            ),
          )),
          const SizedBox(height: 15),
          //popular bread
          Container(
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(10)),
            margin: const EdgeInsets.only(bottom: 5, left: 5, right: 5),
            padding: const EdgeInsets.all(5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                //image
                Image.asset('images/baguette.png', height: 60),
                const SizedBox(width: 10),

                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    //name
                    Text(
                      'Baguette BREAD',
                      style: GoogleFonts.aboreto(
                          fontSize: 15,
                          color: Colors.black,
                          fontWeight: FontWeight.bold),
                    ),

                    const SizedBox(height: 5),
                    //price
                    const Text(
                      '\$12.00',
                      style: TextStyle(
                          color: Colors.black, fontWeight: FontWeight.bold),
                    )
                  ],
                ),
                SizedBox(width: 10),
                const Icon(Icons.favorite_border_outlined, size: 30)
              ],
            ),
          )
        ],
      ),
    );
  }
}

breadSpecial.dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import 'bread_model.dart';

class breadSpe extends StatelessWidget {
  void Function()? onTap;
  final Bread bread;

  breadSpe({super.key, required this.bread, required this.onTap});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Container(
          decoration: BoxDecoration(
              color: Colors.grey[200], borderRadius: BorderRadius.circular(25)),
          margin: const EdgeInsets.only(left: 5),
          padding: EdgeInsets.all(8),
          child: Column(
            //crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(padding: EdgeInsets.all(5)),
              Image.asset(bread.imagePath, height: 140),
              Text(
                bread.name,
                style: GoogleFonts.abel(fontSize: 20),
              ),
              SizedBox(
                width: 150,
                height: 75,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "\$" + bread.price,
                      style: const TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 21),
                    ),

                    Row(
                      children: [
                        Text(bread.rating,
                            style: const TextStyle(fontSize: 14)),
                        const Icon(
                          Icons.star,
                          color: Colors.orange,
                        ),
                      ],
                    ),

                    //f
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

breaddetails.dart

import 'package:flutter/material.dart';

import 'bread_model.dart';

class breadDetails extends StatefulWidget {
  final Bread bread;
  const breadDetails(int index, {super.key, required this.bread});

  @override
  State<breadDetails> createState() => _breadDetailsState();
}

class _breadDetailsState extends State<breadDetails> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
    );
  }
}`

bread_model.dart

class Bread {
  String name;
  String price;
  String imagePath;
  String rating;

  Bread(
      {required this.name,
      required this.price,
      required this.imagePath,
      required this.rating});

  String get _name => name;
  String get _price => price;
  String get _imagePath => _imagePath;
  String get _rating => rating;
}

This is Menu.dart and error is error row is which one is i had marked with stars it tells to add 1 more argument it writes that is expected. Also i added other pages. What i have to do for working GestureDetector. If you help me to do beat this, i will so appreciate to you. Thank you guys.

Lastly Error sentences are bottom:

1 positional argument expected by 'breadDetails.new', but 0 found. Try adding the missing argument.

1

There are 1 answers

0
Munsif Ali On BEST ANSWER

breadDetails Widget is excepting one positional parameter int and one named parameter Bread

use this code to navigate to breadDetails widget

MaterialPageRoute(
        builder: (context) => breadDetails(
         index,
         bread: BreadList[index],
        ),
      ),