我想使用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) 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) 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 );\nRun Code Online (Sandbox Code Playgroud)\n\n来自脚手架类
\n\n/// An app bar to display at the top of the scaffold.\nfinal PreferredSizeWidget appBar;\nRun Code Online (Sandbox Code Playgroud)\n 我想在主屏幕上为图像实现英雄动画,同时在对话框的内容中呈现与对话框相同图像的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) 我正在使用管理器类从缓存中提取图像或发出网络请求.我正在使用占位符图像.在检索到正确的图像时,替换占位符图像的最佳方法是什么?
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) 我想创建一个从起始值到结束值动画的数字计数器.我已经研究过使用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的次数(带动画)?类似于汽车里程表的增量.