小编Nis*_*ddy的帖子

为什么 Dart 中的 const Widget 不相同?

当我们调用identical()使用其构造函数创建的两个小部件时const,它返回 false。而在为两个非小部件对象调用相同的方法时,它会返回true

这是为什么 ?

void main() {

  final a = const Center(
    child: const Padding(padding: const EdgeInsets.all(8),)
  );

  final b = const Center(
    child: const Padding(padding: const EdgeInsets.all(8),)
  );

  assert(identical(a, b)); // false


  var a1 = const EdgeInsets.all(8);

  var b1 = const EdgeInsets.all(8);


  assert(identical(a1, b1)); // true

}
Run Code Online (Sandbox Code Playgroud)

[错误:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:'package:todo_improve/main.dart':断言失败:第 17 行 pos 8:'identical(a, b)':不正确。

constants widget dart flutter

4
推荐指数
1
解决办法
396
查看次数

Flutter:使不同 Icon 大小的 IconButton 和 Row 中的 Text 元素居中对齐

Row在 Flutter 应用程序中有这个小部件,带有一些IconButtons

Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: [
    IconButton(
      icon: Icon(Icons.skip_previous,
        color: Colors.amber, size: 35),
      onPressed: () {
        setState(() {
          pageIndex = 1;
        });
      }),
    IconButton(
      icon: Icon(Icons.arrow_left,
        color: Colors.amber, size: 45),
      onPressed: decIndex),
    Text('Page $pageIndex',
      textAlign: TextAlign.center,
      style: TextStyle(
        color: Colors.amber,
        fontSize: 20,
        fontWeight: FontWeight.bold)),
    IconButton(
      icon: Icon(Icons.arrow_right,
        color: Colors.amber, size: 45),
      onPressed: () {
        incIndex(pageNumbers);
      }),
    IconButton(
      icon: Icon(Icons.skip_next,
        color: Colors.amber, size: 35),
      onPressed: () {
        setState(() {
          pageIndex = pageNumbers;
        });
      }),
    IconButton( …
Run Code Online (Sandbox Code Playgroud)

styles row alignment flutter iconbutton

3
推荐指数
1
解决办法
581
查看次数

如何调整 Flutter 表日历的大小

颤振新手。我需要显示一个日历和下面的一些内容,所以我需要使日历更小。我尝试过使用这样的 SizedBox:

Column(
  children: [
    SizedBox(
      height: 500,
      child: TableCalendar(
        firstDay: firstDay,
        lastDay: lastDay,
        focusedDay: focusedDay)),
    Text("Content goes \n\n\n\n\n\n\n\n\n\n\n\n\n\n\nhere")
  ],
),
Run Code Online (Sandbox Code Playgroud)

但这只是剪辑它。如何正确调整日历的大小?

更新: FittedBox 不起作用,如果您输入宽度,它会正确调整大小,但高度仍然只是剪辑

dart flutter

3
推荐指数
1
解决办法
7118
查看次数

错误:无法在“FormState”上调用“save”方法?因为它可能为空

Flutter 表单保存错误有一个 formKey 但我仍然收到错误

这是我的代码

class _TextFormFieldsState extends State<TextFormFields> {
  String _name = "";

  final formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(    
          primaryColor: Colors.red,
          accentColor: Colors.purpleAccent,
          errorColor: Colors.black
      ),
      child: Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: Icon(Icons.save),
        ),
        appBar: AppBar(
          title: Text("Text Form Field"),
        ),
        body: Padding(
          padding: EdgeInsets.all(20),
          child: Form(
            key: formKey,
            autovalidateMode: AutovalidateMode.always,
            child: ListView(
              children: [
                TextFormField(
                  decoration: InputDecoration(
                    prefixIcon: Icon(Icons.account_circle),
                    hintText: "Your Name",
                    labelText: "FullName",
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(10)),
                    ), …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-form-builder flutter-textinputfield

1
推荐指数
1
解决办法
3213
查看次数