小编Alb*_*bal的帖子

如何使用Flutter在iOS和Android上共享图像?

我想使用iOS和Android中的标准共享对话框共享图像.下面的代码主要来自https://pub.dartlang.org/packages/share,我将其用作起点(下面只有Dart和Objective-C).它目前只共享文本.

而不是Image,我不确定是最好的方法,如何将图像转换为Dart中的字节流并在iOS和Android中处理.

static const _kShareChannel = const MethodChannel('example.test.com/share');
Future<Null> shareImage(Image image) {
  assert(image != null);
  return _kShareChannel.invokeMethod('shareImage', image);
}
Run Code Online (Sandbox Code Playgroud)

Objective-C的

static NSString *const PLATFORM_CHANNEL = @"example.test.com/share";

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [GeneratedPluginRegistrant registerWithRegistry:self];

    FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;

    FlutterMethodChannel *shareChannel = [FlutterMethodChannel methodChannelWithName:PLATFORM_CHANNEL
                            binaryMessenger:controller];

    [shareChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
        if ([@"shareImage" isEqualToString:call.method]) {
            [self share:call.arguments withController:[UIApplication sharedApplication].keyWindow.rootViewController];
            result(nil);
        } else {
            result([FlutterError errorWithCode:@"UNKNOWN_METHOD"
                                       message:@"Unknown share method called"
                                       details:nil]);
        }
    }];
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

How do I auto scale down a font in a Text widget to fit the max number of lines?

I'm trying to use BoxFit.scaleDown in a FittedBox's fit property to scale the font down in a Text widget to accommodate strings of varying length.

However, the below code will scale down the entire string and make it fit on one line, For the below example, I would like the font scaled down so that the string can fit on two lines (per maxLines property of the Text widget).

在此处输入图片说明

import 'package:flutter/material.dart';

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

class MyApp extends …
Run Code Online (Sandbox Code Playgroud)

dart flutter

7
推荐指数
3
解决办法
5624
查看次数

DefaultTabController 中 AppBar 周围的填充

I\xe2\x80\x99m 使用 DefaultTabController 和 Scaffold 作为子部件。对于appBar,I\xe2\x80\x99m 使用TabBar。I\xe2\x80\x99d 喜欢在 TabBar 周围添加一些填充,但 appBar 属性需要一个扩展 PreferredSizeWidget 的类。

\n\n

我正在构建的选项卡控制器的示例片段:

\n\n
  new DefaultTabController(\n    length: tabs.length,\n    child: new Scaffold(\n      backgroundColor: const Color(0xFFF3EEE1),\n      appBar: new TabBar(\n        tabs: tabs,\n      ),\n      body: new TabBarView(\n        children: _testPacks.map((TestPack testPack) {\n          return _contentWidget(context: context, testPack: testPack);\n        }).toList(),\n      ),\n    ),\n  );\n
Run Code Online (Sandbox Code Playgroud)\n\n

来自脚手架类

\n\n
/// An app bar to display at the top of the scaffold.\nfinal PreferredSizeWidget appBar;\n
Run Code Online (Sandbox Code Playgroud)\n

dart flutter

5
推荐指数
2
解决办法
8905
查看次数

带AlertDialog的英雄动画

我想在主屏幕上为图像实现英雄动画,同时在对话框的内容中呈现与对话框相同图像的AlertDialog小部件。

我希望演示文稿显示在下面的屏幕截图中。当我点击左下角的图像时,我想使用英雄动画和图像的嵌入式预览以及可以点击以关闭的透明覆盖层。

在此处输入图片说明

以下代码无法执行英雄动画。

class AlertDialogTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Material(
      child: new InkWell(
        child: new Hero(
          tag: "preview",
          child: new Container(
            alignment: FractionalOffset.bottomLeft,
            child: new Image(
              image: new AssetImage('assets/images/theater.png'),
            ),
          ),
        ),
        onTap: () {
          showDialog(
            context: context,
            child: new AlertDialog(
              content: new Hero(
                tag: "preview",
                child: new Image(
                  image: new AssetImage('assets/images/theater.png'),
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

如何自定义TabBar指示器的宽度和高度?

我正在使用TabBar小部件,我想自定义指标的高度和宽度.除了可以修改的颜色外,我看不到任何其他属性.

在此输入图像描述

dart flutter

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

如何使用异步图像更新占位符图像?

我正在使用管理器类从缓存中提取图像或发出网络请求.我正在使用占位符图像.在检索到正确的图像时,替换占位符图像的最佳方法是什么?

final ItemManager _manager;
final Item _item;
var _itemImage =
  new Image.asset('assets/images/icons/ic_placeholder.png');

@override
Widget build(BuildContext context) {
  _loadImage();
  return new Container(
    child: _itemImage,
  );
}

_loadImage() async {
  var file = await _manager.itemImageForImageUrl(_item.imageUrl);
  _stickerImage = new Image.file(file);
}
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

如何创建动画数字计数器?

我想创建一个从起始值到结束值动画的数字计数器.我已经研究过使用Timer但似乎无法正常动画/更新状态.包括十进制值会很好,但是一个简单的整数动画就可以了.

需要动画的数字计数器

double _mileCounter = 643.6;

_animateMileCounter() {
  Duration duration = new Duration(milliseconds: 300);
  return new Timer(duration, _updateMileCounter);
}

_updateMileCounter() {
  setState(() {
    _mileCounter += 1;
  });
}
Run Code Online (Sandbox Code Playgroud)

如何增加计数器X的次数(带动画)?类似于汽车里程表的增量.

dart flutter

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

标签 统计

dart ×7

flutter ×7