Unverified Commit 1ba16d55 authored by amirh's avatar amirh Committed by GitHub

Don't size Android views to (0,0) (#20956)

Virtual displays must have a non zero size. This was causing a crash:
https://github.com/flutter/flutter/issues/20456
parent 3fcc1069
......@@ -100,7 +100,10 @@ class RenderAndroidView extends RenderBox {
Size _currentAndroidViewSize;
Future<Null> _sizePlatformView() async {
if (_state == _PlatformViewState.resizing) {
// Android virtual displays cannot have a zero size.
// Trying to size it to 0 crashes the app, which was happening when starting the app
// with a locked screen (see: https://github.com/flutter/flutter/issues/20456).
if (_state == _PlatformViewState.resizing || size.isEmpty) {
return;
}
......
......@@ -427,7 +427,8 @@ class AndroidViewController {
/// Sizes the Android View.
///
/// `size` is the view's new size in logical pixel, and must not be null.
/// `size` is the view's new size in logical pixel, it must not be null and must
/// be bigger than zero.
///
/// The first time a size is set triggers the creation of the Android view.
Future<void> setSize(Size size) async {
......@@ -435,6 +436,7 @@ class AndroidViewController {
throw new FlutterError('trying to size a disposed Android View. View id: $id');
assert(size != null);
assert(!size.isEmpty);
if (_state == _AndroidViewState.waitingForSize)
return _create(size);
......
......@@ -37,6 +37,26 @@ void main() {
);
});
testWidgets('Zero sized Android view is not created', (WidgetTester tester) async {
final FakePlatformViewsController viewsController = new FakePlatformViewsController(TargetPlatform.android);
viewsController.registerViewType('webview');
await tester.pumpWidget(
const Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
),
),
);
expect(
viewsController.views,
isEmpty,
);
});
testWidgets('Resize Android view', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
final FakePlatformViewsController viewsController = new FakePlatformViewsController(TargetPlatform.android);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment