我一直在努力在Swift中创建一个UIAlertView,但由于某些原因我无法正确获取该声明,因为我收到此错误:
找不到接受提供的参数的'init'的重载
这是我写的方式:
let button2Alert: UIAlertView = UIAlertView(title: "Title", message: "message",
delegate: self, cancelButtonTitle: "OK", otherButtonTitles: nil)
Run Code Online (Sandbox Code Playgroud)
然后打电话给我我正在使用:
button2Alert.show()
Run Code Online (Sandbox Code Playgroud)
截至目前它正在崩溃,我似乎无法使语法正确.
我想在我的Flutter应用程序中使用以下代码显示带有ListView.builder的SimpleDialog:
showDialog(
context: context,
builder: (BuildContext context) {
return new SimpleDialog(
children: <Widget>[
new FittedBox(
child: new ListView(
children: <Widget>[
new Text("one"),
new Text("two"),
],
),
)
],
);
},
);
Run Code Online (Sandbox Code Playgroud)
这给出了这个错误(抱歉,我无法将日志包装为代码,因为Stackoverflow抱怨代码太多了):
══╡通过渲染图书馆的例外情况╞═══════════════════════════════════════════════════════════════════════════════════════════════ =/flutter(4481):在performLayout()期间抛出以下断言:I/flutter(4481):RenderViewport不支持返回内部维度.I/flutter(4481):计算内在维度需要实例化视口的每个子节点,我/ flutter(4481):击败视口的懒惰点.I/flutter(4481):如果你只是想在主轴方向上收缩包装视口,可以考虑一个I/flutter(4481):RenderShrinkWrappingViewport渲染对象(ShrinkWrappingViewport小部件),它实现了I/flutter(4481) :没有实现内在维度API的效果.I/flutter(4481):...我/ flutter(4481):抛出了另一个异常:RenderBox没有布局:RenderPhysicalShape#83d92 relayoutBoundary = up2 NEEDS-PAINT I/flutter(4481):抛出另一个异常:' package:flutter/src/rendering/shifted_box.dart':断言失败:第310行pos 12:'child.hasSize':不是真的.I/flutter(4481):抛出了另一个异常:RenderBox没有布局:RenderPhysicalShape#83d92 relayoutBoundary = up2
我尝试使用具有特定高度和宽度的Container,它可以工作,但我希望ListView能够适应Dialog.
如何在SimpleDialog中包含ListView?
我试图SimpleDialog在敲击之后创建一个FloatingActionButton,但是当按下该按钮时没有任何反应.
我做错了什么?
import "package:flutter/material.dart";
void main() {
runApp(new ControlleApp());
}
class ControlleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) => new Scaffold(
appBar: new AppBar(
backgroundColor: new Color(0xFF26C6DA),
),
floatingActionButton: new FloatingActionButton(
tooltip: 'Add',
child: new Icon(Icons.add),
backgroundColor: new Color(0xFFF44336),
onPressed: (){
new SimpleDialog(
title: new Text('Test'),
children: <Widget>[
new RadioListTile(
title: new Text('Testing'), value: null, groupValue: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Flutter中的圆角创建一个警告对话框,如下面的屏幕截图所示.也在这里添加我的代码,但我的输出与预期的完全不同.有人,请帮帮我.

我的代码在这里.
void _showAlert() {
AlertDialog dialog = new AlertDialog(
content: new Container(
width: 260.0,
height: 230.0,
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
color: const Color(0xFFFFFF),
borderRadius: new BorderRadius.all(new Radius.circular(32.0)),
),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// dialog top
new Expanded(
child: new Row(
children: <Widget>[
new Container(
// padding: new EdgeInsets.all(10.0),
decoration: new BoxDecoration(
color: Colors.white,
),
child: new Text(
'Rate',
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
fontFamily: 'helvetica_neue_light',
),
textAlign: TextAlign.center,
),
),
],
),
), …Run Code Online (Sandbox Code Playgroud) 我用这个方法来显示一个AlertDialog:
_onSubmit(message) {
if (message.isNotEmpty) {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Center(child: Text('Alert')),
content: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children : <Widget>[
Expanded(
child: Text(
message,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.red,
),
),
)
],
),
actions: <Widget>[
FlatButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
}),
FlatButton(
child: Text('Ok'),
onPressed: () {
_inputTextController.clear();
Navigator.of(context).pop();
})
],
);
},
);
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但按钮右对齐,如下图所示:
我想要设置一些按钮的样式,例如一个按钮开始另一个.我搜索了文档,但只找到了如何使它们成为"堆叠全宽按钮".任何想法如何设置按钮的样式?
目前,我有AlertDialog一个IconButton。用户可以单击IconButton,每次单击都有两种颜色。问题是我需要关闭AlertDialog并重新打开以查看颜色图标的状态更改。我想在用户单击时立即更改IconButton的颜色。
这是代码:
bool pressphone = false;
//....
new IconButton(
icon: new Icon(Icons.phone),
color: pressphone ? Colors.grey : Colors.green,
onPressed: () => setState(() => pressphone = !pressphone),
),
Run Code Online (Sandbox Code Playgroud) 我想根据条件显示警告对话框.不基于按钮按下事件等用户交互.
如果在应用程序状态中设置了标志,则会显示数据警告对话框,否则不显示.
下面是我想要显示的示例警报对话框
void _showDialog() {
// flutter defined function
showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return AlertDialog(
title: new Text("Alert Dialog title"),
content: new Text("Alert Dialog body"),
actions: <Widget>[
// usually buttons at the bottom of the dialog
new FlatButton(
child: new Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
Run Code Online (Sandbox Code Playgroud)
我试图在主屏幕小部件的构建方法中调用该方法,但它给了我错误 -
The context used to push or pop routes from the Navigator must be that of a …Run Code Online (Sandbox Code Playgroud) 我想在 Flutter 中显示一个带有 3 个按钮的 AlertDialog,但垂直对齐,因为按钮的文本占用了太多空间。到目前为止,我只让它们水平显示。知道如何解决吗?这篇文章中的解决方案(How to make an AlertDialog in Flutter?)对我来说不起作用,仍然水平显示。
\n\n static Future<void> showLogoutAllDevicesOrOnlyThisDialog(\n BuildContext context) {\n var b1 = FlatButton(\n textColor: Colors.red,\n child: Text(\'Only on this device\'),\n onPressed: () {\n Navigator.of(context).pop();\n RxBus.post(HideSpinnerEvent());\n },\n );\n var b2 = FlatButton(\n textColor: Colors.red,\n child: Text(\'On all devices\'),\n onPressed: () {\n Navigator.of(context).pop();\n RxBus.post(HideSpinnerEvent());\n },\n );\n\n var b3 = FlatButton(\n child: Text(\'Cancel\'),\n onPressed: () {\n Navigator.of(context).pop();\n },\n );\n\n return showDialog<void>(\n context: context,\n builder: (BuildContext context) {\n return AlertDialog(\n title: Text(\'\'),\n …Run Code Online (Sandbox Code Playgroud) 当我尝试在我的 flutter 应用程序的警报对话框中添加带有日期和时间选择器的下拉菜单时,我遇到了 UI 呈现问题。一段时间以来,我一直在尝试解决此问题,但无济于事。这是我得到的输出:
我的代码:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:test_prep/utils/Reminder.dart';
import 'package:intl/intl.dart';
class RemindersPage extends StatefulWidget {
@override
_RemindersPageState createState() => _RemindersPageState();
}
class _RemindersPageState extends State<RemindersPage> {
final TextEditingController _titleController = new
TextEditingController();
List<DropdownMenuItem<Future>> dateDrop = [];
List<DropdownMenuItem<Future>> timeDrop = [];
int selected = null;
void loadDateData() {
dateDrop = [];
dateDrop.add(new DropdownMenuItem(
child: new Text('Pick Date'),
value: _selectedDate(context),
));
}
void loadTimeData() {
timeDrop = [];
timeDrop.add(new DropdownMenuItem(
child: new Text('Pick a Time'), …Run Code Online (Sandbox Code Playgroud) android-alertdialog dart drop-down-menu android-studio flutter
以下是我的 homepage.dart 的一部分,它运行良好,但单击 IconButton 时什么也没有发生。
...
return Scaffold(
appBar: AppBar(
title: Text('Lorem Ipsum'),
leading: IconButton(
icon: Icon(Icons.info),
onPressed: () => AboutWidget(),
),
),
body: ...
Run Code Online (Sandbox Code Playgroud)
这是我的 about_widget.dart 文件,其中定义了我的 AboutWidget。我究竟做错了什么?
import 'package:flutter/material.dart';
class AboutWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('data'),
);
}
}
Run Code Online (Sandbox Code Playgroud) flutter ×9
dart ×5
android ×1
cocoa-touch ×1
flutter-test ×1
ios ×1
listview ×1
swift ×1
uialertview ×1