我是 flutter 的新手,目标是序列化包含其他较小对象的复杂 JSON 对象。
使用json_serializable: ^2.0.0和pubspec.yaml文件看起来像这样。
dependencies:
intl: ^0.15.7
json_annotation: ^2.0.0
built_value: ^6.7.1
flutter:
sdk: flutter
dev_dependencies:
build_runner: ^1.0.0
json_serializable: ^2.0.0
built_value_generator: ^6.7.1
flutter_test:
sdk: flutter
Run Code Online (Sandbox Code Playgroud)
这个user.dart样子
import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';
@JsonSerializable(nullable: false)
class User {
final String firstName;
final String lastName;
final DateTime dateOfBirth;
User({this.firstName, this.lastName, this.dateOfBirth});
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试flutter pub run build_runner build过文件 user.g.dart 没有被创建,我面临着这个问题。
我还添加了build.yaml以下代码的文件
targets: …Run Code Online (Sandbox Code Playgroud) 我正在学习cocos2D-x并正在做一些精灵动画.
我的目标是当单击一个按钮时,对象会向左移动一些动画.现在,如果你快速点击多次,动画会立即发生,看起来熊似乎希望而不是走路.
它的解决方案看起来很简单,我应该检查动画是否已经在运行以及是否应该运行新动画.
以下是我的代码的一部分.
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("AnimBear.plist");
CCSpriteBatchNode* spriteBatchNode = CCSpriteBatchNode::create("AnimBear.png", 8);
this->addChild(spriteBatchNode,10);
CCArray *tempArray = new CCArray();
char buffer[15];
for (int i = 1; i <= 8 ; i++)
{
sprintf(buffer,"bear%i.png", i);
tempArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(buffer));
}
CCAnimation *bearWalkingAnimation = CCAnimation::create(tempArray,0.1f);
startAnimation = CCSprite::createWithSpriteFrameName("bear1.png");
startAnimation->setPosition(ccp (350 , CCDirector::sharedDirector()->getWinSize().height/2 -100));
startAnimation->setScale(0.5f);
startAnimation->setTag(5);
//Animation for bear walking
bearAnimate = CCAnimate::create(bearWalkingAnimation);
Run Code Online (Sandbox Code Playgroud)
这里bearAnimate是一个全局变量,我想知道它是否正在播放动画.
我该怎么做.?
谢谢.
我正在尝试解析一个 JSON 数组,它可以是
{
"config_data": [
{
"name": "illuminate",
"config_title": "Blink"
},
{
"name": "shoot",
"config_title": "Fire"
}
]
}
Run Code Online (Sandbox Code Playgroud)
或者它可以是以下类型
{
"config_data": [
"illuminate",
"shoot"
]
}
Run Code Online (Sandbox Code Playgroud)
甚至
{
"config_data": [
25,
100
]
}
Run Code Online (Sandbox Code Playgroud)
所以为了使用 JSONDecoder 解析这个,我创建了一个结构如下 -
Struct Model: Codable {
var config_data: [Any]?
enum CodingKeys: String, CodingKey {
case config_data = "config_data"
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
config_data = try values.decode([Any].self, forKey: .config_data)
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为Any不确认可解码协议。这可能是什么解决方案。数组可以包含任何类型的数据
目前我[MFMailComposeViewController canSendMail]用来检查设备中是否存在某个帐户.如果不是我希望显示一些警报.
我看到了一个同类型的应用程序,它以本地化语言提供警报"无邮件帐户".
我想要同样的警报,也应该本地化.
它是一些系统警报还是我必须创建一个包含所有本地化字符串的自定义?
这是我正在使用的确切实现
if (![MFMailComposeViewController canSendMail])
return nil;
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
if(mailViewController)
{
//Setting Email Stuff
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个点击和清除游戏.一旦用户点击了一些砖块,就会检查相邻的砖块是否有相同的颜色,并且所有这些砖块都会被立即清除.
这些是使用clearRect()函数清除的.
现在,在上面的砖块和下面的砖块之间留下一个白色的补丁,让上面的砖块悬挂.
现在我想将这些砖块向下移动.我该怎么做呢..?Plz的帮助
我正在用HTML5和JavaScript创建一个简单的游戏.
最初,当游戏开始时,需要一些时间来加载图像和声音.在此期间,用户必须等待并且屏幕看起来不愉快.
所以这就是我想要做的
检查图像和声音的加载状态.
加载资源时增加加载百分比,并分别增加进度条.
我真的没有任何关键从哪里开始.请指导我.
html5 ×2
javascript ×2
canvas ×1
cocos2d-x ×1
flutter ×1
ios ×1
ipad ×1
iphone ×1
json ×1
jsondecoder ×1
objective-c ×1
swift ×1
swift4 ×1