gpt4 book ai didi

flutter - NumberPicker - currentValue 不是粗体

转载 作者:IT王子 更新时间:2023-10-29 06:34:49 30 4
gpt4 key购买 nike

我在映射到类的函数内部使用 NumberPicker 包 ( https://pub.dartlang.org/packages/numberpicker )。它有效,但是选择的 currentValue 不是粗体。我如何分配这个整数的值显然存在问题。但我只是不知道如何纠正它。

结果图片 --> https://imgur.com/a/mXq6Z

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:numberpicker/numberpicker.dart';

void main() {
runApp(
new MaterialApp(
title: "Test",
home: new DataPointPage(),
),
);
}

class DatapointsPoint {
final String type;
final int point1;
const DatapointsPoint({this.type, this.point1});
}

class DataPointPage extends StatefulWidget {
DataPointPage({Key key, this.title}) : super(key: key);
final String title;
@override
_DataPointPageState createState() => new _DataPointPageState();
}

class _DataPointPageState extends State<DataPointPage> {
int total = 100;

int _currentValue;

var datapoints = <DatapointsPoint>[
const DatapointsPoint(type: 'A', point1: 1),
const DatapointsPoint(type: 'B', point1: 2),
];

Card dataCard(DatapointsPoint data) {
return new Card(
child: new Column(
children: <Widget>[
new NumberPicker.integer(
initialValue: _currentValue,
minValue: 1,
maxValue: 5,
onChanged: (newValue) => setState(() {
_currentValue = newValue;
}),
),
],
),
);
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: const Text('myApp'), actions: <Widget>[
new Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Text(
"Total: $total", // <-- Total the point1 integers
style: new TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 20.0),
),
],
),
]),
body: new Column(
children: datapoints.map((DatapointsPoint data) {
_currentValue = data.point1; // need to set initial value before passing data??
return dataCard(data);
}).toList()),
);
}
}

最佳答案

我来晚了一点,但以防其他人引用,如果 initialValue = selectedValue 则只有它改变颜色。

 NumberPicker levelPicker = new NumberPicker.integer(
initialValue: _currentLevel,
minValue: 0,
maxValue: 100,
step: 1,
onChanged: (num) {
setState(() {
_currentLevel = num;
_saveLevel(num);
});
});

关于flutter - NumberPicker - currentValue 不是粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48722376/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com