Home > Net >  flutter: child isn't defined
flutter: child isn't defined

Time:06-24

I'm having trouble in an attempt to add an child but idk why doesn't work unless something is wrong with my numberform.dart

TextFormField(
                      controller: numteamController,
                      validator: (value) {
                        if (value!.isEmpty) {
                          return "Enter Valid Number";
                        } else {
                          return null;
                        }
                      },

                      child: NumberForm(
                        text: "Team Number",
                        formText: "Enter team number",
                        padding: 0,
                      )
                    ),

numberform.dart

    import 'package:flutter/material.dart';

class NumberForm extends StatelessWidget {
  const NumberForm(
      {Key? key,
      required this.text,
      required this.formText,
      required this.padding,
      required TextFormField child})
      : super(key: key);

  final String formText;
  final String text;
  final double padding;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        SizedBox(
          height: padding,
        ),
        Align(
          alignment: Alignment.topLeft,
          child: Padding(
            padding: const EdgeInsets.only(bottom: 10.0, left: 30),
            child: Text(
              text,
              style: const TextStyle(
                fontFamily: "Oxygen",
                fontWeight: FontWeight.bold,
                color: Colors.black,
                fontSize: 20,
              ),
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(bottom: 10.0, right: 30, left: 30),
          child: TextFormField(
            decoration: InputDecoration(
              labelText: formText,
              fillColor: Colors.white,
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(25.0),
                borderSide: const BorderSide(),
              ),
              //fillColor: Colors.green
            ),
            keyboardType: TextInputType.number,
            style: const TextStyle(
              fontFamily: "Poppins",
            ),
          ),
        ),
      ],
    );
  }
},

CodePudding user response:

child: NumberForm(
                        text: "Team Number",
                        formText: "Enter team number",
                        padding: 0,
                       child: TextFormField,//add the textformfield here
                      )

In the numberForm class you have mentioned that a child is required but in the above codea child is missing. Add a key child:null in the above code.

CodePudding user response:

Here you have to know some basic things

  • TextFormField doesn't have child property.
  • Why are using TextFormField child in NumberForm if you are not using it.
  • you can use NumberForm like the below code.
    @override
      Widget build(BuildContext context) {
        return const NumberForm(
          text: "Team Number",
          formText: "Enter team number",
          padding: 0,
        );
      }
  • Related