fix _debugCheckOwnerBuildTargetExists; sync localizations and tests (#12245)
* Revert "When parts of the program are changed in a hot reload, but not executed during the reassemble, warn that a restart may be needed. (#12304)" This reverts commit 90028813a89a3de8154144e6e0f1edbe90dc2e4f. * fix _debugCheckOwnerBuildTargetExists; sync localizations and tests * address comments
This commit is contained in:
parent
2b78675bd8
commit
6ca2e5dc10
@ -3272,29 +3272,28 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
|
|||||||
@mustCallSuper
|
@mustCallSuper
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
assert(_active); // otherwise markNeedsBuild is a no-op
|
assert(_active); // otherwise markNeedsBuild is a no-op
|
||||||
_debugCheckOwnerBuildTargetExists('didChangeDependencies');
|
assert(_debugCheckOwnerBuildTargetExists('didChangeDependencies'));
|
||||||
markNeedsBuild();
|
markNeedsBuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _debugCheckOwnerBuildTargetExists(String methodName) {
|
bool _debugCheckOwnerBuildTargetExists(String methodName) {
|
||||||
assert(() {
|
assert(() {
|
||||||
if (owner._debugCurrentBuildTarget == null) {
|
if (owner._debugCurrentBuildTarget == null) {
|
||||||
throw new FlutterError(
|
throw new FlutterError(
|
||||||
'$methodName for ${widget.runtimeType} was called at an '
|
'$methodName for ${widget.runtimeType} was called at an '
|
||||||
'inappropriate time.\n'
|
'inappropriate time.\n'
|
||||||
'\n'
|
'It may only be called while the widgets are being built. A possible '
|
||||||
'It may only be called while the widgets are being built. A possible '
|
'cause of this error is when $methodName is called during '
|
||||||
'cause of this error is when $methodName is called during '
|
'one of:\n'
|
||||||
'one of:\n'
|
' * network I/O event\n'
|
||||||
'\n'
|
' * file I/O event\n'
|
||||||
' * network I/O event\n'
|
' * timer\n'
|
||||||
' * file I/O event\n'
|
' * microtask (caused by Future.then, async/await, scheduleMicrotask)'
|
||||||
' * timer\n'
|
|
||||||
' * microtask (caused by Future.then, async/await, scheduleMicrotask)'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
}());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a description of what caused this element to be created.
|
/// Returns a description of what caused this element to be created.
|
||||||
@ -3942,7 +3941,7 @@ class InheritedElement extends ProxyElement {
|
|||||||
/// by first obtaining their [InheritedElement] using
|
/// by first obtaining their [InheritedElement] using
|
||||||
/// [BuildContext.ancestorInheritedElementForWidgetOfExactType].
|
/// [BuildContext.ancestorInheritedElementForWidgetOfExactType].
|
||||||
void dispatchDidChangeDependencies() {
|
void dispatchDidChangeDependencies() {
|
||||||
_debugCheckOwnerBuildTargetExists('dispatchDidChangeDependencies');
|
assert(_debugCheckOwnerBuildTargetExists('dispatchDidChangeDependencies'));
|
||||||
for (Element dependent in _dependents) {
|
for (Element dependent in _dependents) {
|
||||||
assert(() {
|
assert(() {
|
||||||
// check that it really is our descendant
|
// check that it really is our descendant
|
||||||
|
@ -206,23 +206,20 @@ class _LocalizationsScope extends InheritedWidget {
|
|||||||
Key key,
|
Key key,
|
||||||
@required this.locale,
|
@required this.locale,
|
||||||
@required this.localizationsState,
|
@required this.localizationsState,
|
||||||
@required this.loadGeneration,
|
@required this.typeToResources,
|
||||||
Widget child,
|
Widget child,
|
||||||
}) : super(key: key, child: child) {
|
}) : super(key: key, child: child) {
|
||||||
assert(localizationsState != null);
|
assert(localizationsState != null);
|
||||||
|
assert(typeToResources != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Locale locale;
|
final Locale locale;
|
||||||
final _LocalizationsState localizationsState;
|
final _LocalizationsState localizationsState;
|
||||||
|
final Map<Type, dynamic> typeToResources;
|
||||||
/// A monotonically increasing number that changes after localizations
|
|
||||||
/// delegates have finished loading new data. When this number changes, it
|
|
||||||
/// triggers inherited widget notifications.
|
|
||||||
final int loadGeneration;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(_LocalizationsScope old) {
|
bool updateShouldNotify(_LocalizationsScope old) {
|
||||||
return loadGeneration != old.loadGeneration;
|
return typeToResources != old.typeToResources;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,11 +442,6 @@ class _LocalizationsState extends State<Localizations> {
|
|||||||
final GlobalKey _localizedResourcesScopeKey = new GlobalKey();
|
final GlobalKey _localizedResourcesScopeKey = new GlobalKey();
|
||||||
Map<Type, dynamic> _typeToResources = <Type, dynamic>{};
|
Map<Type, dynamic> _typeToResources = <Type, dynamic>{};
|
||||||
|
|
||||||
/// A monotonically increasing number that increases after localizations
|
|
||||||
/// delegates have finished loading new data, triggering inherited widget
|
|
||||||
/// notifications.
|
|
||||||
int _loadGeneration = 0;
|
|
||||||
|
|
||||||
Locale get locale => _locale;
|
Locale get locale => _locale;
|
||||||
Locale _locale;
|
Locale _locale;
|
||||||
|
|
||||||
@ -513,7 +505,6 @@ class _LocalizationsState extends State<Localizations> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_typeToResources = value;
|
_typeToResources = value;
|
||||||
_locale = locale;
|
_locale = locale;
|
||||||
_loadGeneration += 1;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -539,7 +530,7 @@ class _LocalizationsState extends State<Localizations> {
|
|||||||
key: _localizedResourcesScopeKey,
|
key: _localizedResourcesScopeKey,
|
||||||
locale: _locale,
|
locale: _locale,
|
||||||
localizationsState: this,
|
localizationsState: this,
|
||||||
loadGeneration: _loadGeneration,
|
typeToResources: _typeToResources,
|
||||||
child: new Directionality(
|
child: new Directionality(
|
||||||
textDirection: _textDirection,
|
textDirection: _textDirection,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
|
@ -159,6 +159,23 @@ Widget buildFrame({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SyncLoadTest extends StatefulWidget {
|
||||||
|
const SyncLoadTest();
|
||||||
|
|
||||||
|
@override
|
||||||
|
SyncLoadTestState createState() => new SyncLoadTestState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SyncLoadTestState extends State<SyncLoadTest> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return new Text(
|
||||||
|
TestLocalizations.of(context).message,
|
||||||
|
textDirection: TextDirection.rtl,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Localizations.localeFor in a WidgetsApp with system locale', (WidgetTester tester) async {
|
testWidgets('Localizations.localeFor in a WidgetsApp with system locale', (WidgetTester tester) async {
|
||||||
BuildContext pageContext;
|
BuildContext pageContext;
|
||||||
@ -205,27 +222,27 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Synchronously loaded localizations in a WidgetsApp', (WidgetTester tester) async {
|
testWidgets('Synchronously loaded localizations in a WidgetsApp', (WidgetTester tester) async {
|
||||||
BuildContext pageContext;
|
final List<LocalizationsDelegate<dynamic>> delegates = <LocalizationsDelegate<dynamic>>[
|
||||||
await tester.pumpWidget(
|
new SyncTestLocalizationsDelegate(),
|
||||||
buildFrame(
|
const DefaultWidgetsLocalizationsDelegate(),
|
||||||
delegates: <LocalizationsDelegate<dynamic>>[
|
];
|
||||||
new SyncTestLocalizationsDelegate()
|
|
||||||
],
|
|
||||||
buildContent: (BuildContext context) {
|
|
||||||
pageContext = context;
|
|
||||||
return new Text(TestLocalizations.of(context).message);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(TestLocalizations.of(pageContext), isNotNull);
|
Future<Null> pumpTest(Locale locale) async {
|
||||||
|
await tester.pumpWidget(new Localizations(
|
||||||
|
locale: locale,
|
||||||
|
delegates: delegates,
|
||||||
|
child: const SyncLoadTest(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
await pumpTest(const Locale('en', 'US'));
|
||||||
expect(find.text('en_US'), findsOneWidget);
|
expect(find.text('en_US'), findsOneWidget);
|
||||||
|
|
||||||
await tester.binding.setLocale('en', 'GB');
|
await pumpTest(const Locale('en', 'GB'));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('en_GB'), findsOneWidget);
|
expect(find.text('en_GB'), findsOneWidget);
|
||||||
|
|
||||||
await tester.binding.setLocale('en', 'US');
|
await pumpTest(const Locale('en', 'US'));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('en_US'), findsOneWidget);
|
expect(find.text('en_US'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user