Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 颤振列表视图项根据文本字段中添加的编号进行更改_Android_Listview_Flutter - Fatal编程技术网

Android 颤振列表视图项根据文本字段中添加的编号进行更改

Android 颤振列表视图项根据文本字段中添加的编号进行更改,android,listview,flutter,Android,Listview,Flutter,我刚刚开始学习颤振,并试图从总体上改进我的编程 正如您在屏幕截图中看到的,我有一个带有按钮的文本字段,然后在该字段下有一个列表视图 在我的应用程序中,我需要列表视图中的一个项目根据患者体重(特别是给定的量)进行更改。如何根据文本字段中给定的权重为每个listview项显示不同的“给定量” 这是我当前的列表项代码和显示它的小条 要显示列表项的小条: import 'package:flutter/material.dart'; import 'package:stafford_county_me

我刚刚开始学习颤振,并试图从总体上改进我的编程

正如您在屏幕截图中看到的,我有一个带有按钮的文本字段,然后在该字段下有一个列表视图

在我的应用程序中,我需要列表视图中的一个项目根据患者体重(特别是给定的量)进行更改。如何根据文本字段中给定的权重为每个listview项显示不同的“给定量”

这是我当前的列表项代码和显示它的小条

要显示列表项的小条:

import 'package:flutter/material.dart';
import 'package:stafford_county_medications/ui/medication_row.dart';
import 'package:stafford_county_medications/model/medication_list.dart';

class HomePageBody extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Expanded(
      child: new Container(
        child: new CustomScrollView(
          scrollDirection: Axis.vertical,
          slivers: <Widget>[
            new SliverPadding(
              padding: const EdgeInsets.symmetric(vertical: 24.0),
              sliver: new SliverFixedExtentList(
                itemExtent: 172.0,
                delegate: new SliverChildBuilderDelegate(
                      (context, index) => new MedicationRow(medications[index]),
                  childCount: medications.length,

                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:stafford_county_medicines/ui/medicing_row.dart”;
导入“包装:stafford_county_药物/model/medicing_list.dart”;
类HomePageBody扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新的扩展(
子容器:新容器(
子项:新自定义滚动视图(
滚动方向:轴垂直,
条子:[
新型轧棉机(
填充:常量边集。对称(垂直:24.0),
条子:新的条子固定扩展列表(
项目范围:172.0,
代表:新SliverChildBuilderDelegate(
(上下文,索引)=>新药物行(药物[索引]),
childCount:药物。长度,
),
),
),
],
),
),
);
}
}
清单项目:

import 'package:flutter/material.dart';
import 'package:stafford_county_medications/model/medication_list.dart';
import 'package:stafford_county_medications/ui/home_page.dart';

class MedicationRow extends StatelessWidget {
  final Medication medication;
  final Medication amountGiven;

  MedicationRow(this.medication);

  @override
  Widget build(BuildContext context) {
    final medicationCardContent = new Container(
      margin: new EdgeInsets.all(16.0),
      constraints: new BoxConstraints.expand(),
      child: new Container(
        height: 4.0,
        child: new Column(
          children: <Widget>[
            new Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                new Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    new Row(
                      children: <Widget>[
                        new Image.asset('assets/img/pill.png', height: 30.0),
                        new Container(width: 5.0),
                        new Text('Medication:',
                            style: new TextStyle(fontWeight: FontWeight.bold)
                        ),
                      ],
                    ),
                    new Container(height: 5.0),
                    new Text(medication.name),
                    new Container(height: 5.0),
                    new Text(medication.name2),
                    new Container(height: 5.0),
                  ],
                ),
                new Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: <Widget>[
                        new Image.asset('assets/img/injection-icon.png',
                            height: 30.0),
                        new Container(width: 5.0),
                        new Text('Dosage:',
                            overflow: TextOverflow.ellipsis,
                            style: new TextStyle(fontWeight: FontWeight.bold),
                        ),
                      ],
                    ),
                    new Container(height: 5.0),
                    new Text(medication.dosage,
                    overflow: TextOverflow.ellipsis),
                    new Container(height: 5.0),
                  ],
                ),
              ],
            ),
            new Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                new Text('Amount to give:'),
                new Text(amountGiven.toString()),
              ],
            ),
          ],
        ),
      ),
    );

    final medicationCard = new Container(
      child: medicationCardContent,
      height: 140.0,
      decoration: new BoxDecoration(
        color: new Color(0xFFFFFFFF),
        shape: BoxShape.rectangle,
        borderRadius: new BorderRadius.circular(8.0),
        boxShadow: <BoxShadow>[
          new BoxShadow(
            color: Colors.black12,
            blurRadius: 10.0,
            offset: new Offset(0.0, 10.0),
          ),
        ],
      ),
    );

    return new Container(
      height: 140.0,
      margin: EdgeInsets.all(16.0),
      child: new Column(
        children: <Widget>[
          medicationCard,
        ],
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“包装:stafford_county_药物/model/medicing_list.dart”;
导入“package:stafford_county_medicines/ui/home_page.dart”;
类MedicationRow扩展了无状态小部件{
最终用药;
最终用药量;
药物行(此为药物);
@凌驾
小部件构建(构建上下文){
最终药物卡片内容=新容器(
边距:所有新边集(16.0),
约束:新建BoxConstraints.expand(),
子容器:新容器(
身高:4.0,
子:新列(
儿童:[
新行(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
新专栏(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
新行(
儿童:[
新Image.asset('assets/img/pill.png',高度:30.0),
新容器(宽度:5.0),
新文本(“药物:”,
样式:新文本样式(fontWeight:fontWeight.bold)
),
],
),
新容器(高度:5.0),
新文本(药物名称),
新容器(高度:5.0),
新文本(药物名称2),
新容器(高度:5.0),
],
),
新专栏(
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
新行(
mainAxisAlignment:mainAxisAlignment.end,
儿童:[
新建Image.asset('assets/img/injection icon.png',
高度:30.0),,
新容器(宽度:5.0),
新文本(“剂量:”,
溢出:TextOverflow.省略号,
样式:新文本样式(fontWeight:fontWeight.bold),
),
],
),
新容器(高度:5.0),
新文本(药物、剂量、,
溢出:text溢出。省略号),
新容器(高度:5.0),
],
),
],
),
新行(
mainAxisAlignment:mainAxisAlignment.space,
儿童:[
新文本('给出的金额:'),
新文本(amountGiven.toString()),
],
),
],
),
),
);
最终药物卡=新容器(
儿童:药物卡片内容,
身高:140.0,
装饰:新盒子装饰(
颜色:新颜色(0xFFFFFF),
形状:BoxShape.rectangle,
边界半径:新边界半径。圆形(8.0),
boxShadow:[
新盒影(
颜色:颜色。黑色,
半径:10.0,
偏移量:新偏移量(0.0,10.0),
),
],
),
);
退回新货柜(
身高:140.0,
边距:所有边缘集(16.0),
子:新列(
儿童:[
药物卡,
],
),
);
}
}

我相信我需要将列表项更改为一个有状态的小部件,但之后我就不知道了。如果我需要添加其他帮助,请让我知道。提前感谢您提供的任何可能的帮助。

在我看来,包含文本编辑器字段和计算按钮和HomePageBody的小部件应该是StateFulWidget,HomePageBody小部件可以有PatientWidget八个成员变量。 按下“计算”按钮,您可以使用setState方法,该方法将自动使用新的PatientView字段重建视图和主页正文 大概是这样的:

class HomePageBodyContainer extends StatefulWidget {
 @override
 State createState ()=> new HomePageBodyContainerState();
}

HomePageBodyContainerState extends State<HomePageBodyContainer>{
 double _patientWeight = 0.0;
 @override
 Widget build(BuildContext context){
  return new Column(
  children: <Widget>[
   ....textfield code
   ....button code
   onPress: (){ setState((){ _patientWeight = double.parse(textFieldsValue); }); },
   ...
   ...
   new HomePageBody(patientWeight: _patientWeight),
]
);
}
}

谢谢你的回答。我会看看这是否能让我达到我想要的目的。:)
class HomePageBody extends StatelessWidget{
   final double patientWeight;
   HomePageBody({@required this.patientWeight});
}