小编Nic*_*ick的帖子

如何使用MediaQuery为Flutter中的文本设置scaleFactor?

借助MediaQuery,我可以获得Samsung S7 Edge屏幕尺寸的高度和宽度,因此可以使用它。但是,如何使用MediaQuery在ListTile中布置多列动态文本呢?在我的演示项目中,我将文本大小设置为12,在Samsung S6中,我遇到了溢出问题... Flutter中文本比例因子的任何信息或示例?

我在这里找到了一个解决方案(Flutter如何处理dpi文本和图像大小的差异),我尝试构建演示项目。S6 textScaleFactor是1.1而S7是1.0 ....

我使用S7文本大小对其进行测试的原始演示应用程序为12。当我尝试在S6中对其进行测试时,我遇到了溢出问题...我需要使用MediaQuery缩小或放大以设置文本缩放系数,以便它可以工作大多数设备没有溢出问题?

在ListTile中,我有一列包含4行单独的文本,并且所有值都来自数据库。如果文本值太长,则在S6设备上会出现溢出问题。所以我的问题是如何使用MediaQuery为Flutter中的文本设置scaleFactor?

更新:

new ListTile(
    trailing: new Icon(Icons.chevron_right),
    onTap: () {

    },
    title: new Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        new Text(
          ‘My Account Details:’,
          style: new TextStyle(
              fontSize: 14.0, fontWeight: FontWeight.bold, color: Colors.black),
          overflow: TextOverflow.fade,
        ),
      ],
    ),
    subtitle: new Column(
      children: <Widget>[
        new Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            new Text(‘Hello Flutter’,
              style: new TextStyle(
                  fontSize: 12.0, color: Colors.black54),
              overflow: TextOverflow.fade,
            ),

            new Text(’Today is **************’,
              style: new TextStyle(
                  fontSize: …
Run Code Online (Sandbox Code Playgroud)

text scale dart flutter

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

如何完全处置我的有状态小组件?

我调用有状态的小部件页面,并从服务器获取一些信息。如果未找到任何信息,则会警告用户没有任何信息。从抽屉后退按钮,我返回上一页。如果我非常快地来回重复,则会在IntelliJ IDE中收到控制台消息错误,如下所示:

E/flutter (22681): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (22681): setState() called after dispose(): _BillsPayWaterState#66be5(lifecycle state: defunct, not mounted)
E/flutter (22681): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback. The preferred solution is to cancel the timer or …
Run Code Online (Sandbox Code Playgroud)

dispose stateful setstate flutter

4
推荐指数
2
解决办法
5124
查看次数

如何在 Dart 或 Flutter 中将日期转换为儒略日期?

我需要将数据作为儒略日期发送到主机。但我不知道如何在 Flutter 或 Dart 中做到这一点。有一个插件,但似乎与 Dart2 不兼容。那么将日期转换为儒略日期的通用版本是什么?

dart flutter

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

如何从 Flutter 中的另一个类访问全局数据?

我有一个简单的类;

import 'dart:io';
class IDCardClass {
  File frontImageFile;
  File backImageFile;
}
Run Code Online (Sandbox Code Playgroud)

front_test.dart类我需要一个数据分配给frontImageFileback_test.dartI类需要将数据分配给backImageFile

在我的课程home.dart或其他***.dart课程中,我需要获取frontImageFile并将backImageFile其展示给用户。

我的问题是如何从 Flutter 中的另一个类访问全局数据?

class global-variables flutter

4
推荐指数
1
解决办法
2万
查看次数

如何使用Flutter webview评估Javascript?

我尝试使用webview evaluateJavascript并出现错误。WebView Controller有2个功能;evaluateJavascript, 和loadUrl。我在 中测试了两者onPageFinished: (url){},因此我可以初始化我的 javascript 代码。文档不清楚。但该错误告诉我缺少一些 pr 未在 webview 插件中实现的内容。我正在尝试加载页面并初始化一些基本的 javascript,以便我可以隐藏页面的某些部分。

\n\n

如何使用Flutter webview评估Javascript?

\n\n

错误:

\n\n
Syncing files to device iPhone X...\nflutter: Page finished loading: https://stackoverflow.com/\n[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: \'javascript:(function() { var head = document.getElementsByClassName(\'top-bar js-top-bar top-bar__network _fixed\')[0].style.display=\'none\'; })()\'\nError Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=TypeError: undefined is not an object (evaluating \'document.getElementsByClassName(\'top-bar js-top-bar top-bar__network _fixed\')[0].style\'), WKJavaScriptExceptionColumnNumber=117, WKJavaScriptExceptionSourceURL=https://stackoverflow.com/, NSLocalizedDescription=A JavaScript …
Run Code Online (Sandbox Code Playgroud)

javascript webview flutter

4
推荐指数
1
解决办法
2万
查看次数

如何解决Flutter下拉按钮溢出问题?

我创建了Flutter表单,并使用flutter构建了一个下拉按钮。我正在将本地子数据丢失到下拉列表中。我的某些下拉菜单项很长。我使用SafeArea和ListView,并且在右边溢出。

另一个问题未提及的部分解决方案,我在这里得到了答案。

知道如何解决吗?

 // TODO: BUILD RUN
        return new Scaffold(
            key: _scaffoldKey,
            body: new SafeArea(
                top: false,
                bottom: false,
                child: new Form(
                    key: _formKey,
                    child: new ListView(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 16.0, vertical: 32.0),
                      children: <Widget>[
                        //TODO: CURRENCY 
                        new FormField<String>(
                          builder: (FormFieldState<String> state) {
                            return InputDecorator(
                              decoration: InputDecoration(
                                labelText: 'CHOOSE CURRENCY',
                                labelStyle: TextStyle(
                                    fontSize: 18.0,
                                    fontWeight: FontWeight.bold,
                                    color: Colors.green.shade700),
                                errorText: state.hasError ? state.errorText : null,
                              ),
                              isEmpty: _mySelectedCurrency == '',
                              child: new DropdownButtonHideUnderline(
                                child: new DropdownButton<String>(
                                  style: TextStyle(
                                    fontSize: 14.0, …
Run Code Online (Sandbox Code Playgroud)

overflow dart dropdown flutter

3
推荐指数
2
解决办法
2609
查看次数

如何将 Flutter 应用程序连接到 tcp 套接字服务器?

我很难将 Flutter 应用程序连接到服务器上的网络 tcp 套接字。我知道我必须使用某种中间选项,以便在 tcp socket 到 flutter 和 Flutter 到 tcp socket 之间转换数据。

任何想法,信息如何实现这一点。问题是如何将 Flutter 应用程序连接到 tcp 套接字服务器?

sockets tcpclient dart flutter

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

如何过滤 List&lt;Map&lt;String, dynamic&gt;&gt; 以获取 Flutter 中的值?

我有一个 json 数据,我正在List<Map<String, dynamic>>使用 await jsonDecode加载.

例如,我有一个;

  1. 金额 = 12500
  2. 口径 = 24

我需要过滤儿子以获得成熟度值:689.19

此外,如果我有一个数量 = 12500 和价值 = 689.19,我需要获得 24 的口径。

如何过滤 List> json 数据以获取 Flutter 中的值?

[
   {"amount": "5000", "caliber": "12", "maturity":  "484.25"},
   {"amount": "5000", "caliber": "24", "maturity":  "275.67"},
   {"amount": "7500", "caliber": "12", "maturity":  "726.38"},
   {"amount": "7500", "caliber": "24", "maturity":  "413.51"},
   {"amount": "10000", "caliber": "12", "maturity":  "968.50"},
   {"amount": "10000", "caliber": "24", "maturity":  "551.35"},
   {"amount": "12500", "caliber": "12", "maturity":  "1210.63"},
   {"amount": "12500", "caliber": …
Run Code Online (Sandbox Code Playgroud)

list filter where flutter

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

如何从 Dart 中的 Future 返回套接字数据?

可能我将数据发送到服务器并使用以下代码在 ============ 行之间获取数据,即使是非常大的数据。这是我的实验,因为我需要一些中间解决方案,以便我可以将 Flutter 应用程序连接到 tcp 套接字。为此,我选择 auqeduct.io。今天来自 Gazi 的帮助我找到了在 ============ 行之间完成我的代码的解决方案。

因为我正在使用 auqeduct,他们的句柄函数看起来像这样。

@override
  Future<RequestOrResponse> handle(Request request) async {
Run Code Online (Sandbox Code Playgroud)

因此,我尝试修改我的代码并使用 Future 将套接字数据作为字符串返回。我可以在 ============ 行之间使用下面的代码获取数据,但是我无法使用 Future _handle(String _request) 异步获取任何数据。

_socket.listen((data) 打印数据无法将数据分配给字符串,因此我无法返回字符串。

作品: print("(1) $_secureResponse");

不起作用: _secureResponse = new String.fromCharCodes(data).trim();

如果我不使用 Future 并将代码放在 main() 中,则一切正常。

在我的测试服务器中,我发送了一个“Hello World”,作为回报,我得到了“欢迎先生/女士”。

我的问题是:如何从 Dart 中的 Future 返回套接字数据?

import 'dart:async';
import 'dart:io';
import 'dart:convert';

Socket socket;
String _errorData;
String _secureResponse;

void main() async {

  var _test = await _handle("Hello World");
  print("Print _test: $_test");

}


Future<String> _handle(String _request) …
Run Code Online (Sandbox Code Playgroud)

sockets future return dart

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

如何使用Flutter AnimationController和Transform旋转图像?

我有星星png图像,我需要使用Flutter AnimationController和Transformer旋转星星。我找不到图像旋转动画的任何文档或示例。

任何想法如何使用Flutter AnimationController和Transform旋转图像?

更新:

class _MyHomePageState extends State<MyHomePage>  with TickerProviderStateMixin {

  AnimationController animationController;

  @override
  void initState() {
    super.initState();
    animationController = new AnimationController(
      vsync: this,
      duration: new Duration(milliseconds: 5000),
    );
    animationController.forward();
    animationController.addListener(() {
      setState(() {
        if (animationController.status == AnimationStatus.completed) {
          animationController.repeat();
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      alignment: Alignment.center,
      color: Colors.white,
      child: new AnimatedBuilder(
        animation: animationController,
        child: new Container(
          height: 80.0,
          width: 80.0,
          child: new Image.asset('images/StarLogo.png'),
        ),
        builder: (BuildContext context, Widget _widget) {
          return …
Run Code Online (Sandbox Code Playgroud)

animation image transform flutter

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