Home > Blockchain >  Flutter: The named parameter 'height' isn't defined
Flutter: The named parameter 'height' isn't defined

Time:11-24

I am learning Flutter and I'm very beginner to it. In my application i create a custom button:

import 'package:flutter/cupertino.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:fruits_market/core/constants.dart';
import 'package:flutter/material.dart';

class CustomGeneralButton extends StatelessWidget {
  const CustomGeneralButton({super.key,this.text});
  final String? text;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: KMainColor,
        borderRadius: BorderRadius.circular(8), 
        height: 60,
        width: 100,
        ),
      child: Center(
        child: Text(
          text!,
          style: TextStyle(
            fontSize: 14,
            color: const Color(0xffffffff),
            fontWeight: FontWeight.w500,
          ),
          textAlign: TextAlign.left,
          ),
      ),
    );
  }
}

I got this error :

The named parameter 'height' isn't defined

this error appears also with the 'width' property. How to fix it?

CodePudding user response:

BoxDecoration can't use height and width, you need to set this to the Container.

 Container(
    height: 60,
    width: 100,
    decoration: BoxDecoration(
       color: KMainColor,
       borderRadius: BorderRadius.circular(8), 
    ),
  ....
);
  • Related