小编Nic*_*ick的帖子

如何在 Flutter 中在 ListView.builder 的顶部添加填充?

我在 Flutter 项目中主要使用 ListView 和 ListView.builder 。大多数情况下,我使用构建小部件主体部分来放置 ListView 或 ListView.builder。我查看了 Flutter 文档,但没有发现任何信息或示例。

这是一个基本的 ListView 示例。如您所见,ListView 被放置在 body 中。我想要一些身体顶部的填充,然后是 ListView。填充结束,ListView 开始。

如何在 Flutter 中的 ListView.builder 顶部添加填充?

@override
  Widget build(BuildContext context) {
    final title = 'Basic List';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: // how to add some padding here then ListView
             ListView(
          children: <Widget>[
            ListTile(
              leading: Icon(Icons.map),
              title: Text('Map'),
            ),
            ListTile(
              leading: Icon(Icons.photo_album),
              title: Text('Album'),
            ),
            ListTile(
              leading: Icon(Icons.phone),
              title: Text('Phone'),
            ),
          ],
        ),
      ), …
Run Code Online (Sandbox Code Playgroud)

listview padding flutter

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

如何通过Dart中的值获取Map键?

在Dart语言中如何按值获取MAP键?

我有一张地图;

{
  "01": "USD",
  "17": "GBP",
  "33": "EUR"
}
Run Code Online (Sandbox Code Playgroud)

我需要使用值来获取密钥.我怎么做?

dictionary key dart

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

如何在 Flutter DropDown 按钮中搜索

我在本地 json 中有一个国家名称列表。我可以加载我的本地 json 并分配给DropDown button。json 文件中有 193 个国家/地区,例如。如下所示。如果我想选择美国,用户必须一直向下滚动。如何输入国家名称,例如;如果我用户输入 U 或 u,下拉菜单可以进行快速过滤并列出所有以 U 开头的国家/地区,例如美国。如何在 Flutter DropDownbutton 项目中搜索

{
    "country": [
            {
                "countryCode": "AD",
                "countryName": "Andorra",
                "currencyCode": "EUR",
                "isoNumeric": "020"
            },
            {
                "countryCode": "AE",
                "countryName": "United Arab Emirates",
                "currencyCode": "AED",
                "isoNumeric": "784"
            },
            {
                "countryCode": "AF",
                "countryName": "Afghanistan",
                "currencyCode": "AFN",
                "isoNumeric": "004"
            },
Run Code Online (Sandbox Code Playgroud)

filtering dart dropdown flutter

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

如何在 Dart 中替换字符串中间的空格?

我有如下所示的字符串。在 dart trim() 中,它删除了字符串的空白结尾。我的问题是:如何在 Dart 中替换字符串中间的空格

Example-1:

 - Original: String _myText = "Netflix.com.          Amsterdam";
 - Expected Text: "Netflix.com. Amsterdam"


Example-2:

 - Original: String _myText = "The dog has a    long      tail.  ";
 - Expected Text: "The dog has a long tail."
Run Code Online (Sandbox Code Playgroud)

regex whitespace replace dart flutter

9
推荐指数
2
解决办法
6496
查看次数

如何在flutter中使用rootBundle加载图片?

我使用图像插件(图像:^2.0.4)所以我可以在图像上写一些东西,然后将新图像保存到设备或通过邮件发送。我尝试使用“新文件”加载图像,但在 Flutter 上出错。我询问并搜索并得到提示,我可以使用 rootBundle 在 Flutter 中加载图像。我做了,我得到了以下错误。

[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] 未处理的异常:无法加载资产:packages/myAppName/assets/images/ReceiptRaw_1.jpg

当我创建一个简单的 dart 控制台应用程序时,该插件可以工作,但无法使用 flutter 加载。请任何帮助,

这是颤振代码:

    Future<bool> makeReceiptImage() async {

// UPDATE ****************************************

      // load the receipt jpeg
  var imageData = await rootBundle.load('packages/myAppName/dekonts/ReceiptRaw_1.jpg');
  print("imageData: $imageData"); // Prints as imageData: Instance of 
'_ByteDataView'

// UPDATE ****************************************

  Image _receiptImage = await decodeImage(new File(imageData).readAsBytesSync());

      drawString(_receiptImage, arial_48, 440, 30, “Customer Name”, color: 0xFF000000); 

      // Write it to disk as a different jpeg 
      var new_jpeg = await encodeJpg(_receiptImage); 
      String newImagePath = await …
Run Code Online (Sandbox Code Playgroud)

image dart flutter

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

如何在 Dart 语言中按字母顺序对字符串列表进行排序?

我有4家公司,每家公司有10多个分支机构。如果用户选择了一家公司,我需要使用showDialog. 到这里一切都按预期工作。我的问题是我不能List<String>按字母顺序排序。

知道如何在 Dart 中按字母顺序对字符串列表 (List) 进行排序吗?

List<String> _myBranchListName;
Run Code Online (Sandbox Code Playgroud)

sorting string list dart

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

如何在Flutter中发送带附件的邮件?

我发现名为 mailer3 的 dart 插件:“^1.1.9”。之前我在移动临时目录中创建了一个图像。在 Flutter 移动应用程序中,我尝试使用 mailer3 插件将这张保存的图片作为邮件发送。邮件到达目的地,我没有收到错误,但似乎在处理过程中丢失了附件。

\n\n

在 Dart 中它工作得很好并且也发送附件。在 flutter 中,我可以使用临时目录在应用程序中显示图像,但无法附加到邮件。

\n\n

图像位置位于设备的临时文件夹中:

\n\n
    \n
  • \'/data/user/0/com.myApp.myApp/app_flutter/20180700087.jpg\'
  • \n
\n\n

我可以使用下面的代码显示图像:

\n\n
    \n
  • 新的 FileImage(文件(\'$newDekontImage\'),
  • \n
\n\n

错误:

\n\n
E/flutter (21184): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:\nE/flutter (21184): FileSystemException: Cannot open file, path = \'/data/user/0/com.myApp.myApp/app_flutter/20180700087.jpg\' (OS Error: No such file or directory, errno = 2)\n
Run Code Online (Sandbox Code Playgroud)\n\n

如何在 Flutter 中发送带有附件的邮件并提供此问题中提供的信息?

\n\n

颤振代码:

\n\n
// TODO: SEND MAIL\nvoid _sendMail() async {\n  if (!_formKey.currentState.validate()) {\n    return;\n  } else {\n    _formKey.currentState.save();\n\n    var _options = new …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

如何在 Flutter 中发送或接收 xml 文件?

我可以使用 Flutter 发送和接收 JSON、字符串数据。但我找不到任何如何使用 Flutter 发送和接收 xml 文件的信息。

我正在寻找很好的文档和基本的实践示例。有什么帮助吗?

xml https flutter

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

如何创建基于时间的 Flutter 应用程序?

我需要创建一个登录表单。用户成功登录后,我需要启动某种计时器(例如:3 分钟),因此如果用户对应用程序没有反应,或者如果 Flutter 应用程序状态暂停、暂停或不活动超过 3 分钟,则用户没有反应。该应用程序将转到主登录页面。只要用户与应用程序交互,我就需要取消计时器,并且只需要启动计时器应用程序状态是暂停、暂停或不活动。我怎么做?

我尝试实现“WidgetsBindingObserver”,但它看起来不像我想要的那样工作。如果用户成功输入并在应用程序中导航,则 WidgetsBindingObserver 将失败(错误:小部件的状态对象不再出现在小部件树中)。

我的问题是如何实现基于定时的 Flutter 应用程序生命周期,只要用户与应用程序有交互?如果没有用户交互,生命周期计时器将启动,如果在计时器结束之前有用户交互,则必须取消计时器。

class _MyUserHomePageState extends State<MyUserHomePage> with WidgetsBindingObserver {

  AppLifecycleState _appLifecycleState;



@override
void initState() {
  _appStatePasue = false;
  WidgetsBinding.instance.addObserver(this);
  super.initState();
}


// TODO: DID_CHANGE_APP_LIFE_CYCLE
void didChangeAppLifecycleState(AppLifecycleState state) {
  setState(() {
    _appLifecycleState = state;
    if(_appLifecycleState == AppLifecycleState.paused ||
        _appLifecycleState == AppLifecycleState.inactive ||
        _appLifecycleState == AppLifecycleState.suspending) {
      _appStatePasue = true;
      print("timer---fired: $_appLifecycleState");
      _timer = Timer.periodic(Duration(minutes: 1), _capitalCallback);
      print(_appLifecycleState);
    } else {
      _appStatePasue = false;
    }
  });
}

// TODO: APP_LIFE_CYCLE__CALLBACK
void _capitalCallback(_timer) …
Run Code Online (Sandbox Code Playgroud)

lifecycle timer flutter

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

如何制作可编辑的 ListView 项目?

我有动态数据,我正在使用 ListView.builder 来显示用户。我只是使用文本向用户显示数据。只有我添加了一个编辑图标,所以当用户单击该图标时,它使用户能够编辑特定的文本。如何制作可编辑的 ListView 项目?

listview richeditabletext flutter

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