- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
**我是新手,我在这里使用适配器模式,我不知道何时我调用getInitialConfig方法调用主方法时该方法返回null请给我一个帮助**
class below
import 'dart:convert';
// team attribute
class TeamAttributes {
String teamName;
int numOfPlayers;
int wkPlayer;
int captainPlayer;
int currentIndex;
List<String> teamPlayerList = new List<String>();
TeamAttributes({
this.teamName,
this.numOfPlayers,
this.wkPlayer,
this.captainPlayer,
this.currentIndex,
this.teamPlayerList,
});
factory TeamAttributes.fromJson(Map<String, dynamic> json) {
return TeamAttributes(
teamName: json['teamName'],
numOfPlayers: json['numOfPlayers'],
wkPlayer: json['wkPlayer'],
captainPlayer: json['captainPlayer'],
currentIndex: json['currentIndex'],
teamPlayerList: parseList(json['teamPlayerList']), // json['places']);
);
}
Map<String, dynamic> toJson() {
return {
'teamName': teamName,
"numOfPlayers": numOfPlayers,
"wkPlayer": wkPlayer,
"captainPlayer": captainPlayer,
"currentIndex": currentIndex,
"teamPlayerList": teamPlayerList,
};
}
static List<String> parseList(teamPlayerJson) {
List<String> teamPlayerList = new List<String>.from(teamPlayerJson);
return teamPlayerList;
}
}
///setting
class QuickStartSettings {
String matchName;
final BattingRestrictions battingRestrictions;
final BowlingRestrictions bowlingRestrictions;
final Overs overs;
final Balls balls;
final Wides wides;
final NoBalls noBalls;
final Wickets wickets;
QuickStartSettings({
this.matchName,
this.battingRestrictions,
this.bowlingRestrictions,
this.overs,
this.balls,
this.wides,
this.noBalls,
this.wickets,
});
factory QuickStartSettings.fromJson(Map<String, dynamic> json) {
return QuickStartSettings(
matchName: json['matchName'],
battingRestrictions:
BattingRestrictions.fromJson(json['battingRestrictions']),
bowlingRestrictions:
BowlingRestrictions.fromJson(json['bowlingRestrictions']),
overs: Overs.fromJson(json['overs']),
balls: Balls.fromJson(json['balls']),
wides: Wides.fromJson(json['wides']),
noBalls: NoBalls.fromJson(json['noBalls']),
wickets: Wickets.fromJson(json['wickets']),
);
}
Map<String, dynamic> toJson() {
return {
'matchName': matchName,
"battingRestrictions": battingRestrictions,
'bowlingRestrictions': bowlingRestrictions,
"overs": overs,
"balls": balls,
"wides": wides,
"noBalls": noBalls,
"wickets": wickets,
};
}
}
class Wickets {
bool isWicketDismissal;
bool allowBatAgain;
bool lastManStand;
int battingTeamWicketPenalty;
int bowlingTeamWicketBonus;
Wickets({
this.isWicketDismissal,
this.allowBatAgain,
this.lastManStand,
this.battingTeamWicketPenalty,
this.bowlingTeamWicketBonus,
});
factory Wickets.fromJson(Map<String, dynamic> json) {
return Wickets(
isWicketDismissal: json['isWicketDismissal'],
allowBatAgain: json['allowBatAgain'],
lastManStand: json['lastManStand'],
battingTeamWicketPenalty: json['battingTeamWicketPenalty'],
bowlingTeamWicketBonus: json['bowlingTeamWicketBonus'],
);
}
Map<String, dynamic> toJson() {
return {
'isWicketDismissal': isWicketDismissal,
"allowBatAgain": allowBatAgain,
'lastManStand': lastManStand,
"battingTeamWicketPenalty": battingTeamWicketPenalty,
"bowlingTeamWicketBonus": bowlingTeamWicketBonus,
};
}
}
class NoBalls {
bool alwaysRebowl;
bool rebowlLastBall;
bool rebowlForLastOver;
int noBallValue;
bool isBallFacedCountedForBatsman;
NoBalls({
this.alwaysRebowl,
this.rebowlLastBall,
this.rebowlForLastOver,
this.noBallValue,
this.isBallFacedCountedForBatsman,
});
factory NoBalls.fromJson(Map<String, dynamic> json) {
return NoBalls(
alwaysRebowl: json['alwaysRebowl'],
rebowlLastBall: json['rebowlLastBall'],
rebowlForLastOver: json['rebowlForLastOver'],
noBallValue: json['noBallValue'],
isBallFacedCountedForBatsman: json['isBallFacedCountedForBatsman'],
);
}
Map<String, dynamic> toJson() {
return {
'alwaysRebowl': alwaysRebowl,
"rebowlLastBall": rebowlLastBall,
'rebowlForLastOver': rebowlForLastOver,
"noBallValue": noBallValue,
"isBallFacedCountedForBatsman": isBallFacedCountedForBatsman,
};
}
}
class Wides {
bool alwaysRebowl;
bool rebowlLastBall;
bool rebowlForLastOver;
int wideValue;
bool isBallFacedCountedForBatsman;
Wides({
this.alwaysRebowl,
this.rebowlLastBall,
this.rebowlForLastOver,
this.wideValue,
this.isBallFacedCountedForBatsman,
});
factory Wides.fromJson(Map<String, dynamic> json) {
return Wides(
alwaysRebowl: json['alwaysRebowl'],
rebowlLastBall: json['rebowlLastBall'],
rebowlForLastOver: json['rebowlForLastOver'],
wideValue: json['wideValue'],
isBallFacedCountedForBatsman: json['isBallFacedCountedForBatsman'],
);
}
Map<String, dynamic> toJson() {
return {
'alwaysRebowl': alwaysRebowl,
"rebowlLastBall": rebowlLastBall,
'rebowlForLastOver': rebowlForLastOver,
"wideValue": wideValue,
"isBallFacedCountedForBatsman": isBallFacedCountedForBatsman,
};
}
}
class Balls {
int ballsPerOver;
int ballsLastOver;
Balls({
this.ballsPerOver,
this.ballsLastOver,
});
factory Balls.fromJson(Map<String, dynamic> json) {
return Balls(
ballsPerOver: json['ballsPerOver'],
ballsLastOver: json['ballsLastOver'],
);
}
Map<String, dynamic> toJson() {
return {
'ballsPerOver': ballsPerOver,
"ballsLastOver": ballsLastOver,
};
}
}
class Overs {
int numOfOvers;
bool isUnlimitedOvers;
Overs({
this.numOfOvers,
this.isUnlimitedOvers,
});
factory Overs.fromJson(Map<String, dynamic> json) {
return Overs(
numOfOvers: json['numOfOvers'],
isUnlimitedOvers: json['isUnlimitedOvers'],
);
}
Map<String, dynamic> toJson() {
return {
'numOfOvers': numOfOvers,
"isUnlimitedOvers": isUnlimitedOvers,
};
}
}
class BowlingRestrictions {
bool maxOverWarning;
int maxOverWarningCount;
BowlingRestrictions({
this.maxOverWarning,
this.maxOverWarningCount,
});
factory BowlingRestrictions.fromJson(Map<String, dynamic> json) {
return BowlingRestrictions(
maxOverWarning: json['maxOverWarning'],
maxOverWarningCount: json['maxOverWarningCount'],
);
}
Map<String, dynamic> toJson() {
return {
'maxOverWarning': maxOverWarning,
"maxOverWarningCount": maxOverWarningCount,
};
}
}
class BattingRestrictions {
bool maxBallWarning;
int maxBallWarningCount;
bool maxOverWarning;
int maxOverWarningCount;
bool maxRunsWarning;
int maxRunsWarningCount;
bool forceRetAfterWarning;
BattingRestrictions({
this.maxBallWarning,
this.maxBallWarningCount,
this.maxOverWarning,
this.maxOverWarningCount,
this.maxRunsWarning,
this.maxRunsWarningCount,
this.forceRetAfterWarning,
});
factory BattingRestrictions.fromJson(Map<String, dynamic> json) {
return BattingRestrictions(
maxBallWarning: json['maxBallWarning'],
maxBallWarningCount: json['maxBallWarningCount'],
maxOverWarning: json['maxOverWarning'],
maxOverWarningCount: json['maxOverWarningCount'],
maxRunsWarning: json['maxRunsWarning'],
maxRunsWarningCount: json['maxRunsWarningCount'],
forceRetAfterWarning: json['forceRetAfterWarning'],
);
}
Map<String, dynamic> toJson() {
return {
'maxBallWarnings': maxBallWarning,
"maxBallWarningCount": maxBallWarningCount,
"maxOverWarning": maxOverWarning,
"maxOverWarningCount": maxOverWarningCount,
"maxRunsWarnings": maxRunsWarning,
"maxRunsWarningCount": maxRunsWarningCount,
"forceRetAfterWarning": forceRetAfterWarning,
};
}
}
// QuickStartModel
class QuickStartModel {
final TeamAttributes leftTeam;
final TeamAttributes rightTeam;
final QuickStartSettings settings;
String tossWonBy;
String tossDecision;
QuickStartModel({
this.tossWonBy,
this.tossDecision,
this.leftTeam,
this.rightTeam,
this.settings,
});
factory QuickStartModel.fromJson(Map<String, dynamic> json) {
return QuickStartModel(
leftTeam: TeamAttributes.fromJson(json['leftTeam']),
rightTeam: TeamAttributes.fromJson(json['rightTeam']),
settings: QuickStartSettings.fromJson(json['settings']),
tossWonBy: json['tossWonBy'],
tossDecision: json['tossDecision'],
);
}
Map<String, dynamic> toJson() {
return {
'leftTeam': leftTeam,
"rightTeam": rightTeam,
"settings": settings,
"tossWonBy": tossWonBy,
"tossDecision": tossDecision,
};
}
}
moke json class below
//moke Api
class QuickStartApi {
final String _quickStartJson = '''
{
"tossDecision": "xs",
"tossWonBy": "as",
"leftTeam": {
"teamName": "Team A",
"numOfPlayers": 11,
"wkPlayer": 1,
"captainPlayer": 1,
"currentIndex": 1,
"teamPlayerList": [
"Player 1",
"Player 2",
"Player 3",
"Player 4",
"Player 5",
"Player 6",
"Player 7",
"Player 8",
"Player 9",
"Player 10",
"Player 11"
]
},
"rightTeam": {
"teamName": "Team B",
"numOfPlayers": 11,
"currentIndex": 1,
"captainPlayer": 1,
"wkPlayer": 1,
"teamPlayerList": [
"Player 1",
"Player 2",
"Player 3",
"Player 4",
"Player 5",
"Player 6",
"Player 7",
"Player 8",
"Player 9",
"Player 10",
"Player 11"
]
},
"settings": {
"matchName": 'FootBall',
"battingRestrictions": {
"maxBallWarning": true,
"maxBallWarningCount": 5,
"maxOverWarning": true,
"maxOverWarningCount": 7,
"maxRunsWarning": true,
"maxRunsWarningCount": 9,
"forceRetAfterWarning": true
},
"bowlingRestrictions": { "maxOverWarning": true, "maxOverWarningCount": 5 },
"overs": { "isUnlimitedOvers": true, "numOfOvers": 10 },
"balls": { "ballsLastOver": 1, "ballsPerOver": 1 },
"wides": {
"alwaysRebowl": true,
"rebowlLastBall": false,
"rebowlForLastOver": false,
"wideValue": 10,
"isBallFacedCountedForBatsman": false
},
"noBalls": {
"alwaysRebowl": true,
"rebowlLastBall": false,
"rebowlForLastOver": false,
"noBallValue": 10,
"isBallFacedCountedForBatsman": false
},
"wickets": {
"isWicketDismissal": true,
"allowBatAgain": true,
"lastManStand": false,
"battingTeamWicketPenalty": 5,
"bowlingTeamWicketBonus": 5
}
}
}
''';
String getQuickStartJson() {
return _quickStartJson;
}
}
Adapater pattern abstract class below
//Adapater
abstract class QuickStartAdapter {
QuickStartModel getInitialConfig();
}
abstract class implement below
//adapter impl
class QuickStartRemote extends QuickStartAdapter {
final QuickStartApi _api = QuickStartApi();
@override
QuickStartModel getInitialConfig() {
var quickStartJSON = _api.getQuickStartJson();
var quickStartList = _parseQuickStartJson(quickStartJSON);
print(quickStartList);
return quickStartList;
}
QuickStartModel _parseQuickStartJson(String quickStartJSON) {
// final Map<String, dynamic> quickStartDecodedJson =
// json.decode(quickStartJSON);
var quickStartDecodedJson =
json.decode(quickStartJSON) as Map<String, dynamic>;
print(quickStartDecodedJson);
var quickStartModel = QuickStartModel.fromJson(quickStartDecodedJson);
print(quickStartModel.settings.matchName);
return quickStartModel;
}
}
main method call getInitialConfig method below
void main() {
QuickStartAdapter adapter;
adapter.getInitialConfig();
QuickStartModel abc = adapter.getInitialConfig();
print(abc);
}
最佳答案
因为您从未将adapter
变量分配给任何值,所以您可以在这里找到问题。
void main() {
QuickStartAdapter adapter; // <- your problem
adapter.getInitialConfig();
QuickStartModel abc = adapter.getInitialConfig();
}
QuickStartAdapter
继承的类的实例(因为该类本身是
abstract
并将其分配给
adapter
变量。
QuickStartRemote
实例(从QuickStartAdapter扩展而来)并将其分配给变量:
void main() {
QuickStartAdapter adapter = QuickStartRemote();
adapter.getInitialConfig();
QuickStartModel abc = adapter.getInitialConfig();
print(abc);
}
"matchName": 'FootBall',
"matchName": "FootBall",
关于dart - 未捕获的TypeError:无法在dart中读取nullError的属性 'getInitialConfig',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61094314/
我有一个相当冗长的命令行程序,它需要用户输入参数,然后使用这些参数进行处理。我想做的是将程序拆分为交互式和非交互式。我试图这样做,并打算让非交互式程序“调用”交互式程序并使用结果(参数),基于这些参数
谁能解释为什么我们在构造函数的参数中使用大括号。 class Cars { String carName; bool isAuto; // create the constructor
我想知道是否有Dart函数,例如PHP的 strrev()。如果没有,您能否请向我展示任何源代码如何自行实现? 谢谢。 最佳答案 我还没有在API中找到一个新的Dart用户(截至今天下午)。但是,以任
我有一个组件,我想根据一个 bool 值绑定(bind)一个不同的 css 类。我的组件代码中有以下内容: bindCssClass(div, "open", this, "task.isOpen")
我一直在研究如何在dart中播放.wav文件,并且已经能够通过dart:html库中定义的AudioElement成功完成此操作。但是,我对使用dart:web_audio库感兴趣,并且遇到了所有这些
Dart 是否旨在实现许多与 Haxe 相同的功能,以便能够针对其他语言和运行时?它是语言和工具的既定目标还是已知目标? 最佳答案 不。Dart 专门针对 web 应用程序开发(更具体地说,客户端 w
我正在尝试让 dart 正常工作。作为编辑器,我想使用 emacs dart-mode。我有两个关于在没有 dart 编辑器的情况下使用 dart 的问题: 1) 我是否需要手动调用 dart2js,
我正在使用列表来创建墨水瓶按钮。我想将列表放在一个单独的 dart 文件中,并将该文件导入到我使用列表的文件中。我不知道如何导入列表。 https://pastebin.com/mf0kvsGu 我制
我正在编写一个 flutter 应用程序,它通过蓝牙 (FlutterBlue) 向设备发送命令。该设备控制一些 LED。通信总体上运行良好,但是:在用户界面上,我有一个控制光强度的 slider 。
我正在使用来自 Get started: command-line and server apps | Dart 的说明.运行 dart --version 时,我得到: Dart VM versio
var c 返回 3 但 10/7=1.4285,其余为 0.4285,operator % 有错误? void main() { var a = 10; var b = 7; var c
如文档中所述: The const keyword isn’t just for declaring constant variables. You can also use it to create
在 Dart 中,我如何最好地编写相当于(不可变/值/非对象) 的代码输出或引用参数 ? 例如在 C#-ish 中,我可能会编码: function void example() { int re
Dart 支持的多重继承机制有哪些? 最佳答案 不,Dart 不支持多重实现继承。 Dart 具有接口(interface),并且与大多数其他类似语言一样,它具有多个接口(interface)继承。
我正在寻找有关如何制作可以采用位置子参数的 web 组件的资源。就像是: {{value}} // this could be any uneditable element {{value}
使用polymer.dart 的Dart 应用程序的pubspec.yaml 文件如下所示(来自Polymer.dart Code Lab): name: polymer_and_dart descr
今天我决定开始学习 Dart 语言,我从 Tour 开始,那里有一个例子: // These work in a const string. const aConstNum = 0; const aC
我正在查找字符串类和其他一些资源,试图了解如何格式化字符串。首先,我试图将数字填充到字符串中,但不是精度。 例子: int a = 0, b = 5, c = 15, d = 46; String
我知道的大部分是Javascript。我相信“列表”是 Dart 最接近数组的东西,但它们在技术上是一样的吗?将它们视为数组是错误的吗?同样, map 会被视为对象吗?我意识到可能存在差异,但进行这种
现在,白色背景刺痛了我的眼睛,因为这是一个looong的黑夜。是否可以从 Dart 编辑器 (v 0.1) 更改主题(更改为更暗的主题)?选择背景颜色和语法高亮怎么样? 最佳答案 是的,这是可能的,我
我是一名优秀的程序员,十分优秀!