Home > Enterprise >  when i try to add more than 1 textbuttons to a single column It shows The named parameter 'chil
when i try to add more than 1 textbuttons to a single column It shows The named parameter 'chil

Time:10-18

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

void main() => runApp(const CustomXylophoneApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(

      home: Scaffold(
        body:

        SafeArea(
          child: Column(
            children: <Widget>[
              TextButton(
                onPressed: () {
                  AudioCache player = AudioCache();
                  player.play('assets_note1.wav');

                  TextButton.styleFrom(foregroundColor: Colors.red);
                },
              ),
              TextButton(
                onPressed: () {
                  AudioCache player = AudioCache();
                  player.play('assets_note2.wav');

                  TextButton.styleFrom(foregroundColor: Colors.blue);
                },
              ),
              TextButton(
                onPressed: () {
                  AudioCache player = AudioCache();
                  player.play('assets_note3.wav');

                  TextButton.styleFrom(foregroundColor: Colors.blueGrey);
                },
              ),
              TextButton(
                onPressed: () {
                  AudioCache player = AudioCache();
                  player.play('assets_note4.wav');

                  TextButton.styleFrom(foregroundColor: Colors.green);
                },
              ),
              TextButton(
                onPressed: () {
                  AudioCache player = AudioCache();
                  player.play('assets_note5.wav');

                  TextButton.styleFrom(foregroundColor: Colors.teal);
                },
              ),
               TextButton(
                onPressed: () {
                  AudioCache player = AudioCache();
                  player.play('assets_note6.wav');

                  TextButton.styleFrom(foregroundColor: Colors.blueAccent);
                },
              ),
              TextButton(
                onPressed: () {
                  AudioCache player = AudioCache();
                  player.play('assets_note7.wav');

                  TextButton.styleFrom(foregroundColor: Colors.pink);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

CodePudding user response:

You need to call child for each TextButton like I am using Text widget on it

TextButton(
  onPressed: () {
    AudioCache player = AudioCache();
    player.play('assets_note1.wav');

    TextButton.styleFrom(foregroundColor: Colors.red);
  },
  child: Text("Button Name"), //this
),

More about TextButton

CodePudding user response:

add child property in TextButton like this

  • Related