小编Vic*_*tiz的帖子

Flutter 防止在按下后关闭对话框

我正在使用showDialog函数来构建一个对话框,但是我需要避免当用户按下后退按钮时,对话框没有关闭,这是我的代码:

showDialog(
      barrierDismissible: false,
      context: context,

      builder: (BuildContext context) {
        // return object of type Dialog
        return AlertDialog(
          title: new Text("Hello"),
          content: new SingleChildScrollView(
            child: Container(),
          actions: <Widget>[
            // usually buttons at the bottom of the dialog

            new FlatButton(
              child: new Text("Close"),
              onPressed: () {
              },
            ),
          ],
        );
      },
    );
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它不关闭?

flutter

9
推荐指数
3
解决办法
3820
查看次数

Flutter FormatException:意外字符(在字符 1 处)

在颤振中,我使用了一个 php 文件,该文件从 db 查询返回一个 json 响应,但是当我尝试解码 json 时,我收到此错误:

E/flutter ( 8294): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled
Exception: FormatException: Unexpected character (at character 1)
E/flutter ( 8294): [{"0":"PRUEBA","usu_nombre":"PRUEBA"}]
E/flutter ( 8294): ^
Run Code Online (Sandbox Code Playgroud)

这是我的飞镖功能:

Future<String> iniciarSesion() async{
var usuario = textUsuario.text;
var password = textPassword.text;
var nombreUsuario;
var url ="http://192.168.1.37/usuario.php";

//Metodo post
var response = await http.post(
    url,
    headers:{ "Accept": "application/json" } ,
    body: { "usuario": '$usuario',"password": '$password'},
    encoding: Encoding.getByName("utf-8")
);
  List data = json.decode(response.body);
}
Run Code Online (Sandbox Code Playgroud)

和我的 php 文件中的代码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

include_once …
Run Code Online (Sandbox Code Playgroud)

json http flutter

6
推荐指数
3
解决办法
4万
查看次数

Flutter 如何在按下后执行功能

当用户在我的 flutter 应用程序中按下后退按钮时,我需要调用一个函数,在带有 java 的 android 中我可以使用以下代码来实现它

@Override
public void onBackPressed() {
//some function
}
Run Code Online (Sandbox Code Playgroud)

颤振中有类似的东西吗?

flutter

6
推荐指数
2
解决办法
3219
查看次数

如何解决颤振中“只能在初始值设定项中访问静态成员”?

我正在开发一个 flutter 应用程序,我需要在其中扫描一些条形码,因此,为此,我使用了一个名为 barcode_scan ( https://pub.dartlang.org/packages/barcode_scan )的插件。因此,当我尝试从存储在步骤列表中的 RaisedButton 调用函数时,问题就出现了,因为我需要在 Stepper 小部件中显示该按钮,当我调用函数以在 onPressed、Android studio 上初始化条形码扫描仪时显示此消息“只能在初始化程序中访问静态成员”。

init条码扫描器的功能:

Future scan() async {
try {
  String barcode = await BarcodeScanner.scan();
  setState(() => this.barcode = barcode);
} on PlatformException catch (e) {
  if (e.code == BarcodeScanner.CameraAccessDenied) {
    setState(() {
      this.barcode = 'The user did not grant the camera permission!';
    });
  } else {
    setState(() => this.barcode = 'Unknown error: $e');
  }
} on FormatException{
  setState(() => this.barcode = 'null (User returned using the "back"-button before …
Run Code Online (Sandbox Code Playgroud)

android flutter

3
推荐指数
1
解决办法
6577
查看次数

Flutter onChange 执行两次

我有一个文本字段,它有 onChange 属性,当它检测到文本有一个 \n 执行一个函数时,问题是这个函数被执行了两次,应该提到,在那个函数中,我清理了文本的文本控制器。

TextField(
  maxLines: null,
  controller: codigoController,
  autofocus: true,
  onChanged: (text) {
    if (text.contains('\n')) {
      test();
    }
  },
),
Run Code Online (Sandbox Code Playgroud)
 _test() {
    print("hello");
    codigoController.clear();
  }
Run Code Online (Sandbox Code Playgroud)

android flutter

1
推荐指数
1
解决办法
1953
查看次数

标签 统计

flutter ×5

android ×2

http ×1

json ×1