简体   繁体   中英

The named parameter 'child' is required, but there's no corresponding argument. (Documentation) Try adding the required argument. FlatButton flutter

So I've tried remaking a project I had but with newer versions of plugins and flutter, which led to some problems of course haha, now I'm dealing with the last issue (I hope so) to which I cant find an answer.

part of it in main.dart:

  Expanded buildKey(Color a, int num){
    return Expanded(
      child: FlatButton(
          color: a,
          onPressed: () {
            playSound(num);

          }),);}

part of pubspec.yaml

version: 1.0.0+1

environment:
  sdk: ">=2.17.5 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.5
  english_words: ^4.0.0
  audioplayers: ^1.0.1

it requires implementing a child to the flatbutton even though in older versions this code worked just fine, I don't know what child widget to implement w/o making any drastic changes

I appreciate any help regarding this topic, if you need any extra information just tell me and ill provide it.

FlatButton is deprecated, I recommended use TextButton like this:

TextButton(
    style:
        ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.red)),
    onPressed: (){}, child: SizedBox(),
  ),

but you can use FlatButton with empty child like this:

FlatButton(
          color: a,
          onPressed: () {
            playSound(num);

          },
          child: SizedBox()
)

child is Widget . However, Flutter recommends using TextButton rather than FlatButton .

FlatButton(
          onPressed: (){},
          child: Text("Button"),
        ),

TextButton(
          onPressed: (){},
          child: Text("Button"),
        ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM