forked from firka/flutter
Migrate flutter_localizations to null safety. (#68645)
Migrate flutter_localizations to null safety.
This commit is contained in:
@@ -382,15 +382,20 @@ $factoryDeclaration
|
||||
///
|
||||
/// Used by [generateGetter] below.
|
||||
String generateType(Map<String, dynamic> attributes) {
|
||||
bool optional = false;
|
||||
String type = 'String';
|
||||
if (attributes != null) {
|
||||
optional = attributes.containsKey('optional');
|
||||
switch (attributes['x-flutter-type'] as String) {
|
||||
case 'icuShortTimePattern':
|
||||
return 'TimeOfDayFormat';
|
||||
type = 'TimeOfDayFormat';
|
||||
break;
|
||||
case 'scriptCategory':
|
||||
return 'ScriptCategory';
|
||||
type = 'ScriptCategory';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 'String';
|
||||
return type + (optional ? '?' : '');
|
||||
}
|
||||
|
||||
/// Returns the appropriate name for getters with the given attributes.
|
||||
|
||||
@@ -16,7 +16,6 @@ HeaderGenerator generateCupertinoHeader = (String regenerateInstructions) {
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
|
||||
@@ -40,14 +39,14 @@ ConstructorGenerator generateCupertinoConstructor = (LocaleInfo locale) {
|
||||
/// For details on the meaning of the arguments, see [GlobalCupertinoLocalizations].
|
||||
const CupertinoLocalization${locale.camelCase()}({
|
||||
String localeName = '$localeName',
|
||||
@required intl.DateFormat fullYearFormat,
|
||||
@required intl.DateFormat dayFormat,
|
||||
@required intl.DateFormat mediumDateFormat,
|
||||
@required intl.DateFormat singleDigitHourFormat,
|
||||
@required intl.DateFormat singleDigitMinuteFormat,
|
||||
@required intl.DateFormat doubleDigitMinuteFormat,
|
||||
@required intl.DateFormat singleDigitSecondFormat,
|
||||
@required intl.NumberFormat decimalFormat,
|
||||
required intl.DateFormat fullYearFormat,
|
||||
required intl.DateFormat dayFormat,
|
||||
required intl.DateFormat mediumDateFormat,
|
||||
required intl.DateFormat singleDigitHourFormat,
|
||||
required intl.DateFormat singleDigitMinuteFormat,
|
||||
required intl.DateFormat doubleDigitMinuteFormat,
|
||||
required intl.DateFormat singleDigitSecondFormat,
|
||||
required intl.NumberFormat decimalFormat,
|
||||
}) : super(
|
||||
localeName: localeName,
|
||||
fullYearFormat: fullYearFormat,
|
||||
@@ -64,7 +63,7 @@ ConstructorGenerator generateCupertinoConstructor = (LocaleInfo locale) {
|
||||
const String cupertinoFactoryName = 'getCupertinoTranslation';
|
||||
|
||||
const String cupertinoFactoryDeclaration = '''
|
||||
GlobalCupertinoLocalizations getCupertinoTranslation(
|
||||
GlobalCupertinoLocalizations? getCupertinoTranslation(
|
||||
Locale locale,
|
||||
intl.DateFormat fullYearFormat,
|
||||
intl.DateFormat dayFormat,
|
||||
|
||||
@@ -16,7 +16,6 @@ HeaderGenerator generateMaterialHeader = (String regenerateInstructions) {
|
||||
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
|
||||
@@ -40,15 +39,15 @@ ConstructorGenerator generateMaterialConstructor = (LocaleInfo locale) {
|
||||
/// For details on the meaning of the arguments, see [GlobalMaterialLocalizations].
|
||||
const MaterialLocalization${locale.camelCase()}({
|
||||
String localeName = '$localeName',
|
||||
@required intl.DateFormat fullYearFormat,
|
||||
@required intl.DateFormat compactDateFormat,
|
||||
@required intl.DateFormat shortDateFormat,
|
||||
@required intl.DateFormat mediumDateFormat,
|
||||
@required intl.DateFormat longDateFormat,
|
||||
@required intl.DateFormat yearMonthFormat,
|
||||
@required intl.DateFormat shortMonthDayFormat,
|
||||
@required intl.NumberFormat decimalFormat,
|
||||
@required intl.NumberFormat twoDigitZeroPaddedFormat,
|
||||
required intl.DateFormat fullYearFormat,
|
||||
required intl.DateFormat compactDateFormat,
|
||||
required intl.DateFormat shortDateFormat,
|
||||
required intl.DateFormat mediumDateFormat,
|
||||
required intl.DateFormat longDateFormat,
|
||||
required intl.DateFormat yearMonthFormat,
|
||||
required intl.DateFormat shortMonthDayFormat,
|
||||
required intl.NumberFormat decimalFormat,
|
||||
required intl.NumberFormat twoDigitZeroPaddedFormat,
|
||||
}) : super(
|
||||
localeName: localeName,
|
||||
fullYearFormat: fullYearFormat,
|
||||
@@ -66,7 +65,7 @@ ConstructorGenerator generateMaterialConstructor = (LocaleInfo locale) {
|
||||
const String materialFactoryName = 'getMaterialTranslation';
|
||||
|
||||
const String materialFactoryDeclaration = '''
|
||||
GlobalMaterialLocalizations getMaterialTranslation(
|
||||
GlobalMaterialLocalizations? getMaterialTranslation(
|
||||
Locale locale,
|
||||
intl.DateFormat fullYearFormat,
|
||||
intl.DateFormat compactDateFormat,
|
||||
|
||||
@@ -67,8 +67,9 @@ void validateEnglishLocalizations(File file) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final bool optional = atResource.containsKey('optional');
|
||||
final String description = atResource['description'] as String;
|
||||
if (description == null)
|
||||
if (description == null && !optional)
|
||||
errorMessages.writeln('No description specified for $atResourceId');
|
||||
|
||||
final String plural = atResource['plural'] as String;
|
||||
@@ -78,7 +79,7 @@ void validateEnglishLocalizations(File file) {
|
||||
if (!bundle.containsKey(resourceIdOther))
|
||||
errorMessages.writeln('Default plural resource $resourceIdOther undefined');
|
||||
} else {
|
||||
if (!bundle.containsKey(resourceId))
|
||||
if (!optional && !bundle.containsKey(resourceId))
|
||||
errorMessages.writeln('No matching $resourceId defined for $atResourceId');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user