我正在尝试构建一个页面,用户可以在其中添加和删除列表中的元素。我正在努力解决一个问题。当我删除一个元素时,模型会在 UI 更新时正确更新,但方式错误:仅删除列表的最后一个元素。
我正在使用颤振 1.5.4。
我已经在列表中使用了更简单的元素,并且我尝试仅使用此页面构建一个新项目以消除所有可能的问题,但它仍然无法正常工作。
我也尝试使用列而不是列表,但结果总是一样的。
主要.dart:
import 'package:flutter/material.dart';
import './widget.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
appBar: AppBar(
title: Text('Hello'),
),
body: Center(
child: SectionWidget(),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
小部件.dart:
import 'package:flutter/material.dart';
class SectionWidget extends StatefulWidget {
_SectionWidgetState createState() => new _SectionWidgetState();
}
class _SectionWidgetState extends State<SectionWidget> {
List<String> _items = List<String>();
@override
Widget build(BuildContext context) {
List<Widget> children = [
ListTile( …Run Code Online (Sandbox Code Playgroud) 我正在使用 angular 7 并且我有一个包含两个输入字段的表单,而第一个总是需要的,只有在选中复选框时才需要第二个。
我正在尝试将 FormGroup 与自定义验证器一起使用:
<form [formGroup]="exampleForm">
<mat-form-field>
<input matInput placeholder="first" formControlName="first">
</mat-form-field>
<mat-checkbox [(ngModel)]=" checked" [ngModelOptions]="{standalone:true}">Make second input field required</mat-checkbox>
<mat-form-field>
<input matInput placeholder="second" formControlName="second">
</mat-form-field>
</form>Run Code Online (Sandbox Code Playgroud)
exampleForm: FormGroup;
checked: boolean;
ngOnInit() {
this.exampleForm = new FormGroup({
'second': new FormControl('', [this.validateIfChecked()]),
'first': new FormControl('example', [Validators.required])
});
}
validateIfChecked(): ValidatorFn {
return (control: AbstractControl): {
[key: string]: any
} | null => {
if (this.checked) {
return control.value ? null : {
'err': true
};
}
return null; …Run Code Online (Sandbox Code Playgroud)我有一个带有多个 IconButton 的行,我需要更改它们的颜色和大小。我设法更改了颜色,但无法更改图标大小。
IconTheme(
data: IconThemeData(size: 48.0, color: Colors.yellow),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
IconButton(
icon: Icon(Icons.delete),
onPressed: () => null,
),
IconButton(
icon: Icon(Icons.file_upload),
onPressed: () => _addPhoto(false),
),
IconButton(
icon: Icon(Icons.camera_alt),
onPressed: () => _addPhoto(true),
),
],
),
),
Run Code Online (Sandbox Code Playgroud)
如果我使用 iconSize 在 IconButtons 中设置大小,它会起作用,但使用 IconTheme 则不会。
我该如何解决?