enable lint prefer_final_in_for_each (#47724)
This commit is contained in:
committed by
GitHub
parent
fa337f5922
commit
4f9b6cf017
@@ -20,7 +20,7 @@ class CodeGenerator {
|
||||
final StringBuffer result = StringBuffer();
|
||||
final List<String> words = input.split(RegExp(r'\s+'));
|
||||
String currentLine = words.removeAt(0);
|
||||
for (String word in words) {
|
||||
for (final String word in words) {
|
||||
if ((currentLine.length + word.length) < wrapWidth) {
|
||||
currentLine += ' $word';
|
||||
} else {
|
||||
@@ -37,7 +37,7 @@ class CodeGenerator {
|
||||
/// Gets the generated definitions of PhysicalKeyboardKeys.
|
||||
String get physicalDefinitions {
|
||||
final StringBuffer definitions = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
final String firstComment = wrapString('Represents the location of the '
|
||||
'"${entry.commentName}" key on a generalized keyboard.');
|
||||
final String otherComments = wrapString('See the function '
|
||||
@@ -73,7 +73,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
}
|
||||
}
|
||||
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
printKey(
|
||||
entry.flutterId,
|
||||
entry.keyLabel,
|
||||
@@ -81,7 +81,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
entry.commentName,
|
||||
);
|
||||
}
|
||||
for (String name in Key.synonyms.keys) {
|
||||
for (final String name in Key.synonyms.keys) {
|
||||
// Use the first item in the synonyms as a template for the ID to use.
|
||||
// It won't end up being the same value because it'll be in the pseudo-key
|
||||
// plane.
|
||||
@@ -99,8 +99,8 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
|
||||
String get logicalSynonyms {
|
||||
final StringBuffer synonyms = StringBuffer();
|
||||
for (String name in Key.synonyms.keys) {
|
||||
for (String synonym in Key.synonyms[name].cast<String>()) {
|
||||
for (final String name in Key.synonyms.keys) {
|
||||
for (final String synonym in Key.synonyms[name].cast<String>()) {
|
||||
final String keyName = upperCamelToLowerCamel(synonym);
|
||||
synonyms.writeln(' $keyName: $name,');
|
||||
}
|
||||
@@ -124,7 +124,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of USB HID codes to physical keys.
|
||||
String get predefinedHidCodeMap {
|
||||
final StringBuffer scanCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
scanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: ${entry.constantName},');
|
||||
}
|
||||
return scanCodeMap.toString().trimRight();
|
||||
@@ -133,10 +133,10 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// THis generates the map of Flutter key codes to logical keys.
|
||||
String get predefinedKeyCodeMap {
|
||||
final StringBuffer keyCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
keyCodeMap.writeln(' ${toHex(entry.flutterId, digits: 10)}: ${entry.constantName},');
|
||||
}
|
||||
for (String entry in Key.synonyms.keys) {
|
||||
for (final String entry in Key.synonyms.keys) {
|
||||
// Use the first item in the synonyms as a template for the ID to use.
|
||||
// It won't end up being the same value because it'll be in the pseudo-key
|
||||
// plane.
|
||||
@@ -152,9 +152,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of GLFW number pad key codes to logical keys.
|
||||
String get glfwNumpadMap {
|
||||
final StringBuffer glfwNumpadMap = StringBuffer();
|
||||
for (Key entry in numpadKeyData) {
|
||||
for (final Key entry in numpadKeyData) {
|
||||
if (entry.glfwKeyCodes != null) {
|
||||
for (int code in entry.glfwKeyCodes.cast<int>()) {
|
||||
for (final int code in entry.glfwKeyCodes.cast<int>()) {
|
||||
glfwNumpadMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
}
|
||||
@@ -165,9 +165,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of GLFW key codes to logical keys.
|
||||
String get glfwKeyCodeMap {
|
||||
final StringBuffer glfwKeyCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.glfwKeyCodes != null) {
|
||||
for (int code in entry.glfwKeyCodes.cast<int>()) {
|
||||
for (final int code in entry.glfwKeyCodes.cast<int>()) {
|
||||
glfwKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
}
|
||||
@@ -178,7 +178,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of XKB USB HID codes to physical keys.
|
||||
String get xkbScanCodeMap {
|
||||
final StringBuffer xkbScanCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.xKbScanCode != null) {
|
||||
xkbScanCodeMap.writeln(' ${toHex(entry.xKbScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
@@ -189,9 +189,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Android key codes to logical keys.
|
||||
String get androidKeyCodeMap {
|
||||
final StringBuffer androidKeyCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.androidKeyCodes != null) {
|
||||
for (int code in entry.androidKeyCodes.cast<int>()) {
|
||||
for (final int code in entry.androidKeyCodes.cast<int>()) {
|
||||
androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
}
|
||||
@@ -202,9 +202,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Android number pad key codes to logical keys.
|
||||
String get androidNumpadMap {
|
||||
final StringBuffer androidKeyCodeMap = StringBuffer();
|
||||
for (Key entry in numpadKeyData) {
|
||||
for (final Key entry in numpadKeyData) {
|
||||
if (entry.androidKeyCodes != null) {
|
||||
for (int code in entry.androidKeyCodes.cast<int>()) {
|
||||
for (final int code in entry.androidKeyCodes.cast<int>()) {
|
||||
androidKeyCodeMap.writeln(' $code: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
}
|
||||
@@ -215,9 +215,9 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Android scan codes to physical keys.
|
||||
String get androidScanCodeMap {
|
||||
final StringBuffer androidScanCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.androidScanCodes != null) {
|
||||
for (int code in entry.androidScanCodes.cast<int>()) {
|
||||
for (final int code in entry.androidScanCodes.cast<int>()) {
|
||||
androidScanCodeMap.writeln(' $code: PhysicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of macOS key codes to physical keys.
|
||||
String get macOsScanCodeMap {
|
||||
final StringBuffer macOsScanCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.macOsScanCode != null) {
|
||||
macOsScanCodeMap.writeln(' ${toHex(entry.macOsScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
@@ -239,7 +239,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of macOS number pad key codes to logical keys.
|
||||
String get macOsNumpadMap {
|
||||
final StringBuffer macOsNumPadMap = StringBuffer();
|
||||
for (Key entry in numpadKeyData) {
|
||||
for (final Key entry in numpadKeyData) {
|
||||
if (entry.macOsScanCode != null) {
|
||||
macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
@@ -249,7 +249,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
|
||||
String get macOsFunctionKeyMap {
|
||||
final StringBuffer macOsFunctionKeyMap = StringBuffer();
|
||||
for (Key entry in functionKeyData) {
|
||||
for (final Key entry in functionKeyData) {
|
||||
if (entry.macOsScanCode != null) {
|
||||
macOsFunctionKeyMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
@@ -260,7 +260,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Fuchsia key codes to logical keys.
|
||||
String get fuchsiaKeyCodeMap {
|
||||
final StringBuffer fuchsiaKeyCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.usbHidCode != null) {
|
||||
fuchsiaKeyCodeMap.writeln(' ${toHex(entry.flutterId)}: LogicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
@@ -271,7 +271,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Fuchsia USB HID codes to physical keys.
|
||||
String get fuchsiaHidCodeMap {
|
||||
final StringBuffer fuchsiaScanCodeMap = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.usbHidCode != null) {
|
||||
fuchsiaScanCodeMap.writeln(' ${toHex(entry.usbHidCode)}: PhysicalKeyboardKey.${entry.constantName},');
|
||||
}
|
||||
@@ -282,7 +282,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Web KeyboardEvent codes to logical keys.
|
||||
String get webLogicalKeyMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
|
||||
}
|
||||
@@ -293,7 +293,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Web KeyboardEvent codes to physical keys.
|
||||
String get webPhysicalKeyMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (Key entry in keyData.data) {
|
||||
for (final Key entry in keyData.data) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': PhysicalKeyboardKey.${entry.constantName},");
|
||||
}
|
||||
@@ -304,7 +304,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
/// This generates the map of Web number pad codes to logical keys.
|
||||
String get webNumpadMap {
|
||||
final StringBuffer result = StringBuffer();
|
||||
for (Key entry in numpadKeyData) {
|
||||
for (final Key entry in numpadKeyData) {
|
||||
if (entry.name != null) {
|
||||
result.writeln(" '${entry.name}': LogicalKeyboardKey.${entry.constantName},");
|
||||
}
|
||||
@@ -359,7 +359,7 @@ $otherComments static const LogicalKeyboardKey $constantName = LogicalKeyboardK
|
||||
|
||||
static String _injectDictionary(String template, Map<String, String> dictionary) {
|
||||
String result = template;
|
||||
for (String key in dictionary.keys) {
|
||||
for (final String key in dictionary.keys) {
|
||||
result = result.replaceAll('@@@$key@@@', dictionary[key]);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -53,18 +53,18 @@ class KeyData {
|
||||
/// Parses the given JSON data and populates the data structure from it.
|
||||
KeyData.fromJson(Map<String, dynamic> contentMap) {
|
||||
data = <Key>[
|
||||
for (String key in contentMap.keys) Key.fromJsonMapEntry(key, contentMap[key] as Map<String, List<dynamic>>),
|
||||
for (final String key in contentMap.keys) Key.fromJsonMapEntry(key, contentMap[key] as Map<String, List<dynamic>>),
|
||||
];
|
||||
}
|
||||
|
||||
/// Converts the data structure into a JSON structure that can be parsed by
|
||||
/// [KeyData.fromJson].
|
||||
Map<String, dynamic> toJson() {
|
||||
for (Key entry in data) {
|
||||
for (final Key entry in data) {
|
||||
// Android Key names
|
||||
entry.androidKeyNames = _nameToAndroidName[entry.constantName]?.cast<String>();
|
||||
if (entry.androidKeyNames != null && entry.androidKeyNames.isNotEmpty) {
|
||||
for (String androidKeyName in entry.androidKeyNames) {
|
||||
for (final String androidKeyName in entry.androidKeyNames) {
|
||||
if (_nameToAndroidKeyCode[androidKeyName] != null) {
|
||||
entry.androidKeyCodes ??= <int>[];
|
||||
entry.androidKeyCodes.add(_nameToAndroidKeyCode[androidKeyName]);
|
||||
@@ -79,7 +79,7 @@ class KeyData {
|
||||
// GLFW key names
|
||||
entry.glfwKeyNames = _nameToGlfwName[entry.constantName]?.cast<String>();
|
||||
if (entry.glfwKeyNames != null && entry.glfwKeyNames.isNotEmpty) {
|
||||
for (String glfwKeyName in entry.glfwKeyNames) {
|
||||
for (final String glfwKeyName in entry.glfwKeyNames) {
|
||||
if (_nameToGlfwKeyCode[glfwKeyName] != null) {
|
||||
entry.glfwKeyCodes ??= <int>[];
|
||||
entry.glfwKeyCodes.add(_nameToGlfwKeyCode[glfwKeyName]);
|
||||
@@ -89,7 +89,7 @@ class KeyData {
|
||||
}
|
||||
|
||||
final Map<String, dynamic> outputMap = <String, dynamic>{};
|
||||
for (Key entry in data) {
|
||||
for (final Key entry in data) {
|
||||
outputMap[entry.constantName] = entry.toJson();
|
||||
}
|
||||
return outputMap;
|
||||
@@ -178,7 +178,7 @@ class KeyData {
|
||||
headerFile = headerFile.replaceAllMapped(enumBlock, (Match match) => match.group(1));
|
||||
final RegExp enumEntry = RegExp(r'''AKEYCODE_([A-Z0-9_]+)\s*=\s*([0-9]+),?''');
|
||||
final Map<String, int> result = <String, int>{};
|
||||
for (Match match in enumEntry.allMatches(headerFile)) {
|
||||
for (final Match match in enumEntry.allMatches(headerFile)) {
|
||||
result[match.group(1)] = int.parse(match.group(2));
|
||||
}
|
||||
return result;
|
||||
@@ -193,7 +193,7 @@ class KeyData {
|
||||
// Only get the KEY definitions, ignore the rest (mouse, joystick, etc).
|
||||
final RegExp enumEntry = RegExp(r'''define GLFW_KEY_([A-Z0-9_]+)\s*([A-Z0-9_]+),?''');
|
||||
final Map<String, dynamic> replaced = <String, dynamic>{};
|
||||
for (Match match in enumEntry.allMatches(headerFile)) {
|
||||
for (final Match match in enumEntry.allMatches(headerFile)) {
|
||||
replaced[match.group(1)] = int.tryParse(match.group(2)) ?? match.group(2).replaceAll('GLFW_KEY_', '');
|
||||
}
|
||||
final Map<String, int> result = <String, int>{};
|
||||
|
||||
Reference in New Issue
Block a user