小编the*_*yer的帖子

有没有办法让表单值默认为不可空?

我的表格

  public loginForm = new FormGroup({
    username: new FormControl('', [Validators.required]),
    password: new FormControl('', [Validators.required, Validators.minLength(8)]),
  });
Run Code Online (Sandbox Code Playgroud)

当获取表单的值时,这是它的类型

getRawValue(): {
  username: string | null;
  password: string | null;
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以这样做来抑制空值

  public loginForm = new FormGroup({
    username: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
    password: new FormControl('', { nonNullable: true, validators: [Validators.required, Validators.minLength(8)] }),
  });
Run Code Online (Sandbox Code Playgroud)

但是有没有办法让所有表单控件默认都不可为空呢?

如果我的表单包含很多控件,我将不得不使用 nonNullable: true所有控件

typescript angular

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

Flutter 2 - 如何在新的 TextButton 中制作圆角并为其指定高度

如何在新的 TextButton 中添加给定高度并使其角变圆

这是在现已弃用的 FlatButton 中执行此操作的方法。

FlatButton(
    height: 44,
    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)),
    color: Colors.green[900],
    minWidth: double.infinity,
    onPressed: () => cart.gtynAddToCart(productID),
    child: Text(
      'Button',
      style: TextStyle(color: Colors.white),
    ));
Run Code Online (Sandbox Code Playgroud)

flutter

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

返回后隐藏顶部状态栏

问题是在隐藏它之后,当我通过顶部滑动将它带回来然后保持......

我该如何解决这个问题?也许某种监听器触摸顶部状态栏?

在此输入图像描述

我的代码

class _MyProfileState extends State<MyProfile> {
  @override
  void initState() {
    SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
    super.initState();
  }

  @override
  void dispose() {
    SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My Profile'),
        elevation: 0,
      ),
      body: Container(),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

flutter

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

Flutter 2 - 设置自动完成 TextFormField 的初始值

我不能使用,TextEditingController因为TextFormField使用Autocomplete fieldViewBuilder TextEditingController

Autocomplete(
                optionsBuilder: (TextEditingValue textEditingValue) {
                  if (textEditingValue.text == '') return [];

                  return this
                      .productNames
                      .where((Map<String, dynamic> option) {
                    return option['ar']
                        .toLowerCase()
                        .contains(textEditingValue.text.toLowerCase());
                  });
                },
                fieldViewBuilder: (context, textEditingController,
                        focusNode, onFieldSubmitted) =>
                    TextFormField(                             
                  controller: textEditingController,//uses fieldViewBuilder TextEditingController
                   focusNode: focusNode,
                ),
              ),
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter2.0

5
推荐指数
2
解决办法
1044
查看次数

Flutter GridView 构建器具有动态高度和每行中的统一子项

在此输入图像描述

使用flutter_staggered_grid_view我会得到我不想要的 GRID 1 。

相反,我希望如果BOX 1的高度为 80px,BOX 2的高度为 50px。Box 2 应该将自身扩展为 80px。

而且高度是动态的。

flutter flutter-layout

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

更新到 Angular 13 后出现属性绑定错误

我收到这个错误

属性绑定 ngIf 未被嵌入模板上的任何指令使用。确保属性名称拼写正确并且所有指令都列在“@NgModule.declarations”中

即使你在我跑步时也能正常工作ng serve

在此输入图像描述 在此输入图像描述

当我将 Angular 更新为v13.

我已经尝试重新启动Vscode并重新安装Angular Language Service并安装以前版本的Angular Language Service ...它们都不起作用..

我的app.module.ts

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [CommonModule, BrowserModule, AppRoutingModule],
  providers: [],
  bootstrap: [AppComponent],
  exports: [CommonModule, BrowserModule],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-language-service angular13

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

Flutter 2.0 - 自动完成小部件从右侧退出屏幕

如何使自动完成框与TextField没有特定宽度的自动完成框大小相同,它占用最大宽度。

              Autocomplete(
                optionsBuilder: (TextEditingValue textEditingValue) {
                  if (textEditingValue.text == '') {
                    return ['aa', 'bb', 'cc', 'aa', 'bb', 'cc'];
                  }
                  return ['aa', 'bb', 'cc', 'aa', 'bb', 'cc']
                      .where((String option) {
                    return option
                        .toString()
                        .contains(textEditingValue.text.toLowerCase());
                  });
                },
                onSelected: (option) {
                  print(option);
                },
              ),
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

dart flutter flutter2.0

2
推荐指数
5
解决办法
1053
查看次数