【问题标题】:The named parameter 'fontSize' isn't defined. in flutter code未定义命名参数“fontSize”。在颤振代码中
【发布时间】:2022-01-20 08:48:24
【问题描述】:

要添加 5 个盒子容器显示 xs、s、m、l、xl 尺寸。但代码抛出错误。我应该在哪里纠正这个?请参阅此处的图片。我添加了一个容器来创建它们。我是 Flutter 新手,任何人都可以帮助 我该如何解决这个问题。

错误 >> 命名参数“fontSize”未定义。在颤振代码中 错误>>未定义命名参数'fontWeight'。

 import 'package:flutter/material.dart';


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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
    backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: Colors.pinkAccent,

        ),
          body: Column(
              children: <Widget>[
          Expanded(
          child: Container(height: MediaQuery.of(context).size.height*.8,
          padding: EdgeInsets.all(10.0),

          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/images/image23.png"),
              //fit: BoxFit.fitHeight,

            ),
          ),

        ),

          ),
                Stack(
                  alignment: Alignment.bottomRight,
                  children: <Widget>[
                    // Max Size
                    Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(30.0),
                        color: Colors.red.shade50,

                      ),
                      alignment: const Alignment (1,1),
                      height: 400,
                      width: 350,

                      child: Column(
                      children: const [
                        Padding(
                       padding: const EdgeInsets.fromLTRB(10, 40, 100, 40),
                              child: Text(
                       "Summer  Collections",
                      style: TextStyle(
                          fontSize: 24,
                   color: Color(0xff262626),
                       fontWeight: FontWeight.w700),
                          textAlign: TextAlign.left,
    ),
    ),
                        Padding(
                          padding: const EdgeInsets.fromLTRB(0, 0, 270, 100),
                          child: Text(
                            "Sizes",
                            style: TextStyle(
                                fontSize: 12,
                                color: Color(0xff262626),
                                fontWeight: FontWeight.w700),
                            textAlign: TextAlign.left,
                          ),
                        ),
                            ],
                          ),
                        )

                    Container(
                        child: Row(
                          children: [
                            Container(
                                height:49, width: 49,
                                decoration: BoxDecoration(
                                    color: Color.fromRGBO(228, 228, 228, 1),
                                    borderRadius: BorderRadius.circular(10)
                                ),
                                child:const Center(
                                  child:Text("xs",
                                      fontSize:20,
                                      fontWeight:FontWeight.bold

                                  ),
                                ),
                            )

    ],




    )),
                    Padding(
                      padding: const EdgeInsets.fromLTRB(230, 110, 0, 40),
                      child: ElevatedButton(
                        onPressed: () {},
                        child: const Text(
                          "Add to Cart ",
                        ),
                        style: ElevatedButton.styleFrom(
                            primary: Colors.black,
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.only(
                                    topLeft: Radius.circular(30),
                                    bottomRight: Radius.circular(20))),
                            padding: const EdgeInsets.all(15)),
                      ),
                    ),



               ]
                    ),

                  ],
                ),



    );
  }
}

【问题讨论】:

    标签: flutter


    【解决方案1】:

    这是使用<strong>TextStyle</strong> 的正确方法。 reference.

    Text(
        'text',
         style: TextStyle(
                 fontSize: 20,
                 fontWeight: FontWeight.bold),
         ),
    

    【讨论】:

      【解决方案2】:

      你应该使用 TextStyle

      Text(
         "your text here" , 
          style: TextStyle(
              fontsize: ,
              fontWeight: 
               ),
           )
      

      【讨论】:

        【解决方案3】:

        您需要TextStyle 来更改字体大小、颜色、字体重量等。

        child: Text("xs", style: TextStyle(
            fontSize: 20,
            fontWeight: FontWeight.bold
          ),
        ),
        

        【讨论】:

          【解决方案4】:

          你写错了代码,试试下面的代码希望对你有帮助。

          请参考 Text Class here

          请参考 TextStyle here

           Center(
            child: Text(
              "xs",
              style: TextStyle(
                fontSize: 20,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          

          你的 Reslt 屏幕->

          【讨论】:

            【解决方案5】:

            将文本样式放入 TextStyle 小部件中。

            这里的问题很简单。文本小部件没有任何属性 fontSize 或字体粗细。相反,它是 TextStyle 小部件。

            这就是它的工作原理

            const Center(
              child: Text("xs",
              style: TextStyle(
                fontSize: 22,
                fontWeight: FontWight.bold
              
              )
            )

            【讨论】:

              【解决方案6】:

              这是Text小部件的textStyle的props,所以首先你要给Text小部件的textstyle,然后设置这个。

               Text(
              "Helo world",
              style: TextStyle(
                fontSize: 30,
                fontWeight: FontWeight.normal,
              )),
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2022-06-30
                • 2021-05-01
                • 2021-01-17
                • 1970-01-01
                • 2022-01-04
                • 2020-09-26
                相关资源
                最近更新 更多