gpt4 book ai didi

flutter - 如何调用 CupertinoPicker

转载 作者:行者123 更新时间:2023-12-03 04:08:57 26 4
gpt4 key购买 nike

当按下某个按钮时,我想显示 CupertinoPicker。
但是我不知道我应该在哪里实现 CupertinoPicker。

下面的代码是我不知道我写在哪里调用的代码示例。

showCupertinoModalPopup<String>(
context: context,
builder:(BuildContext context){
return _buildBottomPicker(CupertinoPicker(
onSelectedItemChanged: (value){
setState((){
selectedValue = value;
});
},
itemExtent: 32.0,
children: const[
Text('Item01'),
Text('Item02'),
Text('Item03'),
],
));
},
);

最佳答案

这是按下按钮时启动cupertino选择器的完整可行的演示。希望这能解决您的疑问。

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: WeightSelect(),
debugShowCheckedModeBanner: false,
);
}
}

class WeightSelect extends StatefulWidget {
@override
_WeightSelectState createState() => _WeightSelectState();
}

class _WeightSelectState extends State<WeightSelect> {
int selectedValue;

showPicker() {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return CupertinoPicker(
backgroundColor: Colors.white,
onSelectedItemChanged: (value) {
setState(() {
selectedValue = value;
});
},
itemExtent: 32.0,
children: const [
Text('Item01'),
Text('Item02'),
Text('Item03'),
],
);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Cupertino picker demo"),
),
body: Column(
children: <Widget>[
const SizedBox(height: 10.0),
Text("Selected: $selectedValue"),
const SizedBox(height: 10.0),
Center(
child: RaisedButton(
onPressed: showPicker,
child: Text("Show picker"),
),
),
],
),
);
}
}

关于flutter - 如何调用 CupertinoPicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59558536/

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