标签: flutter

将元素大小调整为屏幕宽度/高度的百分比

是否有一种简单的(非LayoutBuilder)方法来调整元素相对于屏幕大小(宽度/高度)的大小?例如:如何将CardView的宽度设置为屏幕宽度的65%.

它不能在build方法内部完成(显然),所以它必须推迟到post build.是否有一个像这样的逻辑的首选位置?

flutter

94
推荐指数
10
解决办法
7万
查看次数

Row内的TextField导致布局异常:无法计算大小

我得到一个渲染异常,我不明白如何修复.我正在尝试创建一个包含3行的列.

行[图片]

行[TextField]

行[按钮]

这是构建容器的代码:

Container buildEnterAppContainer(BuildContext context) {
    var container = new Container(
      padding: const EdgeInsets.all(8.0),
      child: new Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          buildImageRow(context),
          buildAppEntryRow(context),
          buildButtonRow(context)
        ],
      ),
    );
    return container;
  }
Run Code Online (Sandbox Code Playgroud)

和我的buildAppEntryRow文本容器的代码

Widget buildAppEntryRow(BuildContext context) {
    return new Row(
      children: <Widget>[
        new TextField(
          decoration: const InputDecoration(helperText: "Enter App ID"),
          style: Theme.of(context).textTheme.body1,
        )
      ],
    );
  }
Run Code Online (Sandbox Code Playgroud)

当我运行时,我得到以下异常:

I/flutter ( 7674): BoxConstraints forces an infinite width.
I/flutter ( 7674): These invalid constraints were provided to RenderStack's layout() function by the …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

Flutter App 卡在“正在运行 Gradle 任务‘assembleDebug’...”

当我运行应用程序时,它卡住了

Launching lib\main.dart on Lenovo A319 in debug mode...
Running Gradle task 'assembleDebug'...
(This is taking an unexpectedly long time.)
Run Code Online (Sandbox Code Playgroud)

它从不初始化 Gradle 和依赖项

yaml gradle flutter flutter-dependencies

94
推荐指数
9
解决办法
12万
查看次数

Flutter 和 Android:您的构建当前配置为使用 Java 17.0.2 和 Gradle 7.0.2

我在 Flutter 的 Android 部分得到了这个。

Unsupported Java. 
Your build is currently configured to use Java 17.0.2 and Gradle 7.0.2.

Possible solution:
 - Open Gradle wrapper settings, change `distributionUrl` property to use compatible Gradle version and reload the project
Run Code Online (Sandbox Code Playgroud)

请告知解决方案。我真的很感激你的回答。

java android gradle kotlin flutter

94
推荐指数
5
解决办法
15万
查看次数

Scaffold.of()使用不包含Scaffold的上下文调用

你可以看到我的按钮在Scaffold的体内.但是我得到了这个例外:

Scaffold.of()使用不包含Scaffold的上下文调用.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('SnackBar Playground'),
      ),
      body: Center(
        child: RaisedButton(
          color: Colors.pink,
          textColor: Colors.white,
          onPressed: _displaySnackBar(context),
          child: Text('Display SnackBar'),
        ),
      ),
    );
  }
}

_displaySnackBar(BuildContext context) {
  final snackBar = SnackBar(content: Text('Are you talkin\' to …
Run Code Online (Sandbox Code Playgroud)

scaffold snackbar flutter

91
推荐指数
12
解决办法
3万
查看次数

错误“术语‘flutterfire’未被识别为 cmdlet、函数、脚本文件或可操作程序的名称”

我正在尝试在我的根项目中安装 flutterfire_cli,所以我输入了以下命令:

FirebaseFirestore firestore = FirebaseFirestore.instance;
Run Code Online (Sandbox Code Playgroud)

之后,这是控制台会话(PowerShell):

FirebaseFirestore firestore = FirebaseFirestore.instance;
Run Code Online (Sandbox Code Playgroud)

输出:

cd C:\Users\PC\Desktop\eventually
dart pub global activate flutterfire_cli
Run Code Online (Sandbox Code Playgroud)

为了修复该警告,我将C:\Users\PC\AppData\Local\Pub\Cache\bin添加到系统变量环境中的Path环境变量中。(但这不起作用,我仍然收到警告)

接下来,我尝试使用以下命令生成firebase_options.dart文件,如文档所述:

Package flutterfire_cli is currently active at version 0.1.1+2.
Resolving dependencies...
The package flutterfire_cli is already activated at newest available version.
To recompile executables, first run `global deactivate flutterfire_cli`.
Installed executable flutterfire.
Warning: Pub installs executables into C:\Users\PC\AppData\Local\Pub\Cache\bin, which is not on your path.
You can fix that by adding that directory …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-tools flutter

91
推荐指数
8
解决办法
17万
查看次数

在 Android 12 模拟器上运行时,为什么我会在日志中看到 EGL_emulation app_time_stats?

在运行 Android 12 的模拟器上测试 Flutter 应用程序时,我会定期(大约每秒)在日志中看到类似这样的行:

D/EGL_emulation(32175): app_time_stats: avg=312.93ms min=133.69ms max=608.57ms count=4
Run Code Online (Sandbox Code Playgroud)

它们是什么意思,我该如何关闭它们?我从未在 Android 11 模拟器上见过它们,所以我猜测它与 Android 12 有关?

android android-emulator logcat flutter android-12

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

颤动给容器圆形边框

我正在制作容器,我给了它一个边框,但我会很高兴有圆形边框。

这就是我现在所拥有的

Container(
      width: screenWidth / 7,
      decoration: BoxDecoration(
        border: Border.all(
          color: Colors.red[500],
        ),
      ),
      child: Padding(
        padding: EdgeInsets.all(5.0),
        child: Column(
          children: <Widget>[
            Text(
              '6',
              style: TextStyle(
                  color: Colors.red[500],
                  fontSize: 25),
            ),
            Text(
             'sep',
              style: TextStyle(
                  color: Colors.red[500]),
            )
          ],
        ),
      ),
    );
Run Code Online (Sandbox Code Playgroud)

我试过在它上面放 cliprrect ,但它把边界剪掉了。有解决方案吗?提前致谢!!!

dart flutter

89
推荐指数
8
解决办法
12万
查看次数

Dart 中的空安全性是什么?

我听说过新的 Dart 空安全语言功能 (NNBD),目前是“ '不可空'实验”。它应该默认引入不可为空

可以在此处找到功能规范,在此处找到语言GitHub 问题

它是如何工作的,我可以在哪里试用?

dart flutter

89
推荐指数
1
解决办法
5万
查看次数

Flutter:使用插件构建需要符号链接支持

每当我尝试安装任何依赖项时,我都会在日志中收到以下错误pubspec.yaml

Building with plugins requires symlink support.

Please enable Developer Mode in your system settings. Run
  start ms-settings:developers
to open settings.
exit code 1
Run Code Online (Sandbox Code Playgroud)

lib文件夹中,有一个名为的文件generated_plugin_registrant.dart也显示错误,可能链接到上面的日志错误。

//
// Generated file. Do not edit.
//

// ignore_for_file: lines_longer_than_80_chars

import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:printing/src/printing_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
  FirebaseCoreWeb.registerWith(registrar);
  PrintingPlugin.registerWith(registrar);
  registrar.registerMessageHandler();
}
Run Code Online (Sandbox Code Playgroud)

dart flutter

89
推荐指数
9
解决办法
14万
查看次数