Home > Software design >  Why I get this error in flutter? Constructor error?
Why I get this error in flutter? Constructor error?

Time:09-07

I'm trying to add some icons to my Flutter code. When I try to add them I get this error message. "Too many positional arguments: 0 expected, but 1 found. Try removing the extra positional arguments, or specifying the name for named arguments." Can someone here tell me what can I do to fix this?

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


class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Padding(padding: EdgeInsets.symmetric(
            horizontal: 32,
            vertical: 16.0,
          )),
          Container(
         color: Colors.grey[900],         
         child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            SizedBox(
              //height: 150,
             // width: 150,
              child: Image.asset('assets/images/logo.png'),
            ),
             Spacer(),
         Text("Escorts",
         style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
         SizedBox(width: 32,),
         Text("Angenturen & Clubs",
         style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
         SizedBox(width: 32,),
         Text("Inserieren",
         style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
         SizedBox(width: 32,),
         Text("Werben",
         style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
         SizedBox(width: 32,),
         Text("Blog",
         style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
         SizedBox(width: 32,),
         Text("Kontakt",
         style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
         Spacer(
         Icon(Icons.heart_broken)
         )
          ],
         ),
          ),
        
          
        ],
      ),
    );
  }
}

CodePudding user response:

You put the Icon inside the Spacer. You can't put anything inside a spacer. Maybe you meant to put it after it? So instead of

Spacer(
  Icon(Icons.heart_broken)
)

do

Spacer(),
Icon(Icons.heart_broken)
     

CodePudding user response:

You set spacer as parent of icon, which is wrong. change it to this:

Stack(
  children: [
   ...
   Spacer(),
   Icon(Icons.heart_broken),
  ],
)
  • Related