0

I'm new to flutter. There was a repetitive construction, I separated it as a method, but I had a problem with the button part. Can you help me?

TextButton buildSportSection(String sport_screen,String sport_name,String name) {
    return TextButton(
          onPressed: () {
           ** Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) =>
                        $sport_screen()));
          },**
          child: Container(
            height: 100,
            decoration: BoxDecoration(
              color: Color(0xFFF7F8F8),
              shape: BoxShape.rectangle,
              borderRadius: BorderRadius.only(
                bottomRight: Radius.circular(50),
                topRight: Radius.circular(50),
              ),
            ),
            child: Row(
              children: [
                Image.asset('assets/images/$name.png'),
                Text("$sport_name",
                    style: GoogleFonts.abhayaLibre(fontSize: 20))
              ],
            ),
          ),
        );
  }
}

enter image description here

There was no problem in the method of the design of this part, but I could not make the text button part.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
fatma
  • 1
  • 1

1 Answers1

0

Can you use the following code. You have to Pass BuildContext and Widgets in the Following manner and you don't have to use $ symbol everywhere.

TextButton buildSportSection(
  BuildContext context, Widget sportScreen, String sportName, String name) {
return TextButton(
  onPressed: () {
    Navigator.push(
        context, MaterialPageRoute(builder: (context) => sportScreen));
  },
  child: Container(
    height: 100,
    decoration: const BoxDecoration(
      color: Color(0xFFF7F8F8),
      shape: BoxShape.rectangle,
      borderRadius: BorderRadius.only(
        bottomRight: Radius.circular(50),
        topRight: Radius.circular(50),
      ),
    ),
    child: Row(
      children: [
        Image.asset('assets/images/$name.png'),
        Text(
          sportName,
          style: GoogleFonts.abhayaLibre(fontSize: 20),
        )
      ],
    ),
  ),
);

}