I need to create table which contains numbers and has square form.
The obvious solution would be to use widget Table, but...
When I use odd size it works, when I use even size it fails with rendering exception.
How to fix it?
void main() => runApp(
MaterialApp(
home: Scaffold(
appBar: new AppBar(title: Text("Table Shulte")),
body: tab(),
)
)
);
Widget tab(){
int N = 6;
Widget table = Table(
children: List.generate(N, (i){
return TableRow(children: List.generate(N, (j) =>
AspectRatio(child:Center(child: Text("${i*N+j+1}", textScaleFactor: 12.0/N,)), aspectRatio: 1.0,)
));
}),
border: TableBorder.all(),
);
return table;
}
I don't understand why this assert failes:
'package:flutter/src/rendering/table.dart': Failed assertion: line 883 pos 16: 'tableWidth >= targetWidth': is not true.
Another exception was thrown: 'package:flutter/src/rendering/table.dart': Failed assertion: line 1126 pos 12: '_rowTops.length == rows + 1': is not true.
Here the log.
I/flutter (10304): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (10304): The following assertion was thrown during performLayout():
I/flutter (10304): 'package:flutter/src/rendering/table.dart': Failed assertion: line 883 pos 16: 'tableWidth >=
I/flutter (10304): targetWidth': is not true.
I/flutter (10304): When the exception was thrown, this was the stack:
I/flutter (10304): #2 RenderTable._computeColumnWidths (package:flutter/src/rendering/table.dart)
I/flutter (10304): #3 RenderTable.performLayout (package:flutter/src/rendering/table.dart:1001:33)
I/flutter (10304): #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (10304): #5 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:141:11)
I/flutter (10304): #6 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:399:7)
I/flutter (10304): #7 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:211:7)
I/flutter (10304): #8 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:355:14)
I/flutter (10304): #9 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (10304): #10 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (10304): #11 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (10304): #12 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (10304): #13 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1143:11)
I/flutter (10304): #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (10304): #15 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (10304): #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (10304): #17 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (10304): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (10304): RenderAspectRatio#eecef NEEDS-LAYOUT NEEDS-PAINT
I/flutter (10304): RenderPositionedBox#1f1ff NEEDS-LAYOUT NEEDS-PAINT
I/flutter (10304): RenderParagraph#8f8f7 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (10304): Another exception was thrown: RenderBox was not laid out: RenderTable#babed relayoutBoundary=up1 NEEDS-PAINT
I/flutter (10304): Another exception was thrown: 'package:flutter/src/rendering/table.dart': Failed assertion: line 1126 pos 12: '_rowTops.length == rows + 1': is not true.
The problem causing the issue is textScaleFactor.
List.generate(index,...) method starts the index from (0).
When we call the textScaleFactor: 12.0/N is not returning a number for the widget therefore it causes an issue.
I simply, modified your tab method as follows and it returns a view now.
Widget tab(){
int N = 6;
Widget table = Table(
children: List.generate(N, (i){
return TableRow(children: List.generate(N+1, (j) =>
AspectRatio(child:Center(child: Text("${i*N+j+1}", textScaleFactor: 12.0/N)), aspectRatio: 1.0)
));
}),
border: TableBorder.all(),
);
return table;
}
Related
Using Provider and FutureBuilder, I just deleted data from database, it got removed at the same time, it shows a red screen with bad state no element. There is no problem to add data, do not show this problem.
Code is given below
stacktrace
ter (12519): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (12519): The following StateError was thrown building ViewNoteScreen(dirty, dependencies:
I/flutter (12519): [_ModalScopeStatus], state: _ViewNoteScreenState#f589b):
I/flutter (12519): Bad state: No element
I/flutter (12519):
I/flutter (12519): The relevant error-causing widget was:
I/flutter (12519): ViewNoteScreen file:///C:/Users/Admin/Desktop/daily%2010/provider_note/lib/main.dart:21:46
I/flutter (12519):
I/flutter (12519): When the exception was thrown, this was the stack:
I/flutter (12519): #0 ListMixin.firstWhere (dart:collection/list.dart:148:5)
I/flutter (12519): #1 Providers.findById (package:provider_note/helper/provider.dart:14:19)
I/flutter (12519): #2 _ViewNoteScreenState.build (package:provider_note/screens/view_note.dart:21:35)
I/flutter (12519): #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4663:28)
I/flutter (12519): #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4546:15)
I/flutter (12519): #5 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
I/flutter (12519): #6 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
I/flutter (12519): #7 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:33)
I/flutter (12519): #8 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:866:20)
I/flutter (12519): #9 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
I/flutter (12519): #10 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
I/flutter (12519): #11 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1056:9)
I/flutter (12519): #12 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:972:5)
I/flutter (12519): #16 _invoke (dart:ui/hooks.dart:253:10)
I/flutter (12519): #17 _drawFrame (dart:ui/hooks.dart:211:3)
I/flutter (12519): (elided 3 frames from dart:async)
I/flutter (12519):
I/flutter (12519): ══════════════════════════════════════════════
BadStateException occurred when list don't contain the item and still someone searching for that
Example:
If orElse not defined in the code and the wrong item gets search which doesn't exist in the list then it shows BadStateException
void main() {
List<String> list = ['red', 'yellow', 'pink', 'blue'];
var newList = list.firstWhere((element) => element.contains('green'));
print(newList);
}
Output:
Uncaught Error: Bad state: No element
Solution: Add orElse
void main() {
List<String> list = ['red', 'yellow', 'pink', 'blue'];
var newList = list.firstWhere((element) => element.contains(''),
orElse: () => 'No matching color found');
print(newList);
}
Output:
No matching color found
I think the easiest way for you is change your home to statefull widget and change this part of your code.
Navigator.pushNamed(
context, ViewNoteScreen.routeName,
arguments: notes.items[i].id).whenComplete(() {
setState(() {});
});
I have just started learning app development via Flutter. I ran into a tutorial to build a simple app.
My task is to add appbar and I did this:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Hello '),
),
),
));
}
I am expecting a simple app bar with the title "Hello ".
I get this error in console :
-I/flutter (17741): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (17741): The following assertion was thrown building MyApp:
I/flutter (17741): MediaQuery.of() called with a context that does not contain a MediaQuery.
I/flutter (17741): No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of().
I/flutter (17741): This can happen because you do not have a WidgetsApp or MaterialApp widget (those widgets introduce
I/flutter (17741): a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.
I/flutter (17741): The context used was:
I/flutter (17741): Scaffold
I/flutter (17741):
I/flutter (17741): The relevant error-causing widget was:
I/flutter (17741): MyApp file:///E:/Flutter/i_am_rich/lib/main.dart:3:23
I/flutter (17741):
I/flutter (17741): When the exception was thrown, this was the stack:
I/flutter (17741): #0 MediaQuery.of (package:flutter/src/widgets/media_query.dart:798:5)
I/flutter (17741): #1 ScaffoldState.didChangeDependencies (package:flutter/src/material/scaffold.dart:1993:50)
I/flutter (17741): #2 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4376:12)
I/flutter (17741): #3 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (17741): #4 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (17741): #5 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (17741): #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
Reloaded 1 of 478 libraries in 437ms.
I/flutter (17741): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (17741): #8 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)
I/flutter (17741): #9 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)
I/flutter (17741): #10 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter (17741): #11 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter (17741): #12 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
I/flutter (17741): #13 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:850:7)
I/flutter (17741): #15 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
I/flutter (17741): #16 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
I/flutter (17741): #17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
I/flutter (17741): (elided one frame from package dart:async-patch)
I/flutter (17741):
I/flutter (17741):
════════════════════════════════════════════════════════════════════════════════════════════════════
It would be great if you could provide me some insights into this.
Issue was solved on suggestion of #VirenVVarasadiya by running:
flutter clean
flutter run
My app is displaying lots of images, and some urls may not be valid.
This is the code i use to display the image:
(I use the cached_network_image plugin)
CachedNetworkImage(
imageUrl: images.first,
fit: BoxFit.cover,
placeholder: (context, url) => Center(
child: CircularProgressIndicator(),
),
errorWidget: (context, url, error) => Center(
child: const Icon(Icons.error)
)
)
Basically, there is the error that is thrown:
E/flutter (28425): [ERROR:flutter/lib/ui/painting/codec.cc(97)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
I/flutter (28425): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (28425): The following _Exception was thrown resolving an image codec:
I/flutter (28425): Exception: operation failed
I/flutter (28425):
I/flutter (28425): When the exception was thrown, this was the stack:
I/flutter (28425): #0 FileImage._loadAsync (package:flutter/src/painting/image_provider.dart:564:12)
I/flutter (28425): <asynchronous suspension>
I/flutter (28425): #1 FileImage.load (package:flutter/src/painting/image_provider.dart:549:14)
I/flutter (28425): #2 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:105)
I/flutter (28425): #3 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:157:22)
I/flutter (28425): #4 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:82)
I/flutter (28425): #5 SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:38:29)
I/flutter (28425): #6 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:283:30)
I/flutter (28425): #7 _ImageState._resolveImage (package:flutter/src/widgets/image.dart:631:20)
I/flutter (28425): #8 _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:606:5)
I/flutter (28425): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3862:12)
I/flutter (28425): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (28425): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (28425): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (28425): #13 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4883:14)
I/flutter (28425): #14 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (28425): #15 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4601:32)
I/flutter (28425): #16 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4992:17)
I/flutter (28425): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (28425): #18 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (28425): #19 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (28425): #20 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2273:33)
I/flutter (28425): #21 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20)
I/flutter (28425): #22 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:268:5)
I/flutter (28425): #23 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:988:15)
I/flutter (28425): #24 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:928:9)
I/flutter (28425): #25 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:840:5)
I/flutter (28425): #29 _invoke (dart:ui/hooks.dart:209:10)
I/flutter (28425): #30 _drawFrame (dart:ui/hooks.dart:168:3)
I/flutter (28425): (elided 3 frames from package dart:async)
I/flutter (28425):
I/flutter (28425): Path:
I/flutter (28425): /data/user/0/xx.xxxx.xxxxxxxxxxx/cache/libCachedImageData/31c76660-5970-11e9-b769-3943ba44d1cb.html;
I/flutter (28425): charset=UTF-8
I/flutter (28425): ════════════════════════════════════════════════════════════════════════════════════════════════════
Notice that this url give some html... so that's normal
As I do not found any way to handle that error, i tried to use NetworkImageWithRetry from flutter_image package using:
FadeInImage(
placeholder: MemoryImage(kTransparentImage),
image: NetworkImageWithRetry(
imageUrl
),
fit: BoxFit.cover,
fadeInDuration: Duration(milliseconds: 150)
)
There is example of error that is thrown this time:
[ERROR:flutter/lib/ui/painting/codec.cc(97)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
I/flutter (31334): ══╡ EXCEPTION CAUGHT BY PACKAGE:FLUTTER_IMAGE ╞═════════════════════════════════════════════════════
I/flutter (31334): The following FetchFailure was thrown NetworkImageWithRetry failed to load
I/flutter (31334): xxxxxxxxxxxxxxxx :
I/flutter (31334): FetchFailure(
I/flutter (31334): attemptCount: 1
I/flutter (31334): httpStatusCode: null
I/flutter (31334): totalDuration: 0:00:05.969844
I/flutter (31334): originalException: Exception: operation failed
I/flutter (31334): )
I/flutter (31334): ════════════════════════════════════════════════════════════════════════════════════════════════════
This url send html...
The problem is that in release mode, I force close the app in case of any error, so i need to handle them
how can I just handle this types of error ?
The setup
I have to simple routes, FirstRoute and SecondRoute. Each one contains a button to for the navigation. Pressing FirstRoute's button leads to second and vice-versa.
The exception
I am getting an exception when I am trying to navigate from FirstRoute to SecondRoute for the second time (first try is successful). Judging by the message "Cannot install a MaterialPageRoute after disposing it" I somehow disposed a route but I can't figure out which route and how I did that.
Here is the full error log:
══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (26569): The following assertion was thrown while handling a gesture:
I/flutter (26569): Cannot install a MaterialPageRoute<void> after disposing it.
I/flutter (26569): 'package:flutter/src/widgets/routes.dart': Failed assertion: line 175 pos 12:
I/flutter (26569): '!_transitionCompleter.isCompleted'
I/flutter (26569): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (26569): more information in this error message to help you determine and fix the underlying cause.
I/flutter (26569): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (26569): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (26569): When the exception was thrown, this was the stack:
I/flutter (26569): #2 TransitionRoute.install (package:flutter/src/widgets/routes.dart:175:12)
I/flutter (26569): #3 ModalRoute.install (package:flutter/src/widgets/routes.dart:895:11)
I/flutter (26569): #4 NavigatorState.push (package:flutter/src/widgets/navigator.dart:1742:11)
I/flutter (26569): #5 Navigator.push (package:flutter/src/widgets/navigator.dart:1081:34)
I/flutter (26569): #6 _createOnPressed.<anonymous closure> (package:layout_tutorial/main.dart:46:32)
I/flutter (26569): #7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:513:14)
I/flutter (26569): #8 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:568:30)
I/flutter (26569): #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
I/flutter (26569): #10 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:246:9)
I/flutter (26569): #11 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
I/flutter (26569): #12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:436:9)
I/flutter (26569): #13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
I/flutter (26569): #14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
I/flutter (26569): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:214:19)
I/flutter (26569): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:192:22)
I/flutter (26569): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:149:7)
I/flutter (26569): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
I/flutter (26569): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
I/flutter (26569): #23 _invoke1 (dart:ui/hooks.dart:223:10)
I/flutter (26569): #24 _dispatchPointerDataPacket (dart:ui/hooks.dart:144:5)
I/flutter (26569): (elided 5 frames from class _AssertionError and package dart:async)
I/flutter (26569): Handler: onTap
I/flutter (26569): Recognizer:
I/flutter (26569): TapGestureRecognizer#1bc15(debugOwner: GestureDetector, state: possible, won arena, finalPosition:
I/flutter (26569): Offset(164.3, 365.3), sent tap down)
I/flutter (26569): ════════════════════════════════════════════════════════════════════════════════════════════════════
and here is the whole code in case someone wants to reproduce the error:
import 'package:flutter/material.dart';
typedef void OnPressed();
main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
#override
Widget build(BuildContext context) {
return _getRouteScaffold('First route', 'Go to second route',
_createOnPressed(context, route: SecondRoute()));
}
}
class SecondRoute extends StatelessWidget {
#override
Widget build(BuildContext context) {
return _getRouteScaffold(
'Second route', 'Back to first route', _createOnPressed(context));
}
}
Widget _getRouteScaffold(String title, String buttonText, OnPressed function) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: RaisedButton(
child: Text(buttonText),
onPressed: function,
)),
);
}
OnPressed _createOnPressed(BuildContext context, {StatelessWidget route}) {
OnPressed function;
if (route != null) {
MaterialPageRoute<void> materialRoute =
MaterialPageRoute<void>(builder: (context) => route);
function = () => Navigator.push(context, materialRoute);
} else {
function = () => Navigator.pop(context);
}
return function;
}
All of those approaches are imho not best practices, but I am sure there was a reason to build this, the way it is built. Anyway I found the error in line 16:
_createOnPressed(context, route: SecondRoute()));
You pass this function to the button, which will always execute with the same SecondRoute. After a MaterialPageRoute has been disposed, it cannot be used anymore. Therefore you'll have to build a new route each time.
To do this you can simply warp your method call in another closure, which will then be executed on press, an initiate a new instance. I've simply adjusted line 16 to fix your error:
() => _createOnPressed(context, route: SecondRoute())());
Cheers :)
I want to have a dialog that takes my user through an authentication flow. It will need the following widgets:
Choose auth method (Google, Facebook, email, phone, etc)
Enter email address
Enter phone number
Enter code from (email/phone)
What I'm trying to do is create an AlertDialog with a PageView widget that will be navigated via the PageController (I have set physics: NeverScrollableScrollPhysics() to prevent the user from scrolling around). The whole idea here is I'd like the dialog to always remain the same size (which I understand PageView will measure all the children and should allow me to do this.
I tried creating the PageView with 3 Text widgets and I get the following error:
I/flutter (16052): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (16052): The following assertion was thrown during performLayout():
I/flutter (16052): RenderViewport does not support returning intrinsic dimensions.
I/flutter (16052): Calculating the intrinsic dimensions would require instantiating every child of the viewport, which
I/flutter (16052): defeats the point of viewports being lazy.
I/flutter (16052): If you are merely trying to shrink-wrap the viewport in the main axis direction, consider a
I/flutter (16052): RenderShrinkWrappingViewport render object (ShrinkWrappingViewport widget), which achieves that
I/flutter (16052): effect without implementing the intrinsic dimension API.
I/flutter (16052):
I/flutter (16052): When the exception was thrown, this was the stack:
I/flutter (16052): #0 RenderViewportBase.debugThrowIfNotCheckingIntrinsics.<anonymous closure> (package:flutter/src/rendering/viewport.dart:299:9)
I/flutter (16052): #1 RenderViewportBase.debugThrowIfNotCheckingIntrinsics (package:flutter/src/rendering/viewport.dart:309:6)
I/flutter (16052): #2 RenderViewportBase.computeMaxIntrinsicWidth (package:flutter/src/rendering/viewport.dart:321:12)
I/flutter (16052): #3 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #4 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #5 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #6 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #7 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #8 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #9 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #10 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #11 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #12 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #13 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #14 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #15 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #16 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #17 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #18 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #19 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #20 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #21 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #22 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #23 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #24 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #25 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #26 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #27 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #28 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #29 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #30 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #31 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #32 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #33 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #34 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #35 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #36 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #37 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #38 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #39 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #40 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #41 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #42 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.computeMaxIntrinsicWidth (package:flutter/src/rendering/proxy_box.dart:76:20)
I/flutter (16052): #43 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #44 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #45 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #46 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #47 RenderPadding.computeMaxIntrinsicWidth (package:flutter/src/rendering/shifted_box.dart:163:20)
I/flutter (16052): #48 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #49 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #50 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #51 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #52 RenderFlex.computeMaxIntrinsicWidth.<anonymous closure> (package:flutter/src/rendering/flex.dart:575:60)
I/flutter (16052): #53 RenderFlex._getIntrinsicSize (package:flutter/src/rendering/flex.dart:552:58)
I/flutter (16052): #54 RenderFlex.computeMaxIntrinsicWidth (package:flutter/src/rendering/flex.dart:572:12)
I/flutter (16052): #55 RenderBox._computeIntrinsicDimension.<anonymous closure> (package:flutter/src/rendering/box.dart:1099:23)
I/flutter (16052): #56 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
I/flutter (16052): #57 RenderBox._computeIntrinsicDimension (package:flutter/src/rendering/box.dart:1097:41)
I/flutter (16052): #58 RenderBox.getMaxIntrinsicWidth (package:flutter/src/rendering/box.dart:1281:12)
I/flutter (16052): #59 RenderIntrinsicWidth.performLayout (package:flutter/src/rendering/proxy_box.dart:617:36)
I/flutter (16052): #60 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #61 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #62 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #63 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #64 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #65 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #66 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #67 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #68 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1188:11)
I/flutter (16052): #69 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #70 RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:258:13)
I/flutter (16052): #71 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #72 RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:385:13)
I/flutter (16052): #73 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #74 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
I/flutter (16052): #75 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #76 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
I/flutter (16052): #77 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #78 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #79 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #80 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #81 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #82 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #83 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #84 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #85 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #86 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #87 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #88 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #89 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #90 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16052): #91 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2881:13)
I/flutter (16052): #92 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (16052): #93 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter (16052): #94 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
I/flutter (16052): #95 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
I/flutter (16052): #96 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
I/flutter (16052): #97 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:677:13)
I/flutter (16052): #98 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (16052): #99 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (16052): #100 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (16052): #101 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (16052): #102 _invoke (dart:ui/hooks.dart:154:13)
I/flutter (16052): #103 _drawFrame (dart:ui/hooks.dart:143:3)
I/flutter (16052):
I/flutter (16052): The following RenderObject was being processed when the exception was fired:
I/flutter (16052): RenderIntrinsicWidth#88cfa relayoutBoundary=up6 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): creator: IntrinsicWidth ← Semantics ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
I/flutter (16052): _InkFeatures-[GlobalKey#8e5bb ink renderer] ← NotificationListener<LayoutChangedNotification> ←
I/flutter (16052): CustomPaint ← _ShapeBorderPaint ← PhysicalShape ← _MaterialInterior ← Material ← ConstrainedBox ←
I/flutter (16052): ⋯
I/flutter (16052): parentData: <none> (can use size)
I/flutter (16052): constraints: BoxConstraints(280.0<=w<=331.4, 0.0<=h<=611.4)
I/flutter (16052): size: MISSING
I/flutter (16052): stepWidth: null
I/flutter (16052): stepHeight: null
I/flutter (16052): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (16052): RenderFlex#1cdae NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderPadding#3c952 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderRepaintBoundary#2e299 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderCustomPaint#4dd7f NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderRepaintBoundary#ebf6b NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderPadding#31e20 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderFlex#8072a NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderPadding#a5f11 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): RenderSemanticsAnnotations#f63f2 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16052): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (16052): Another exception was thrown: RenderBox was not laid out: RenderIntrinsicWidth#88cfa relayoutBoundary=up6 NEEDS-PAINT
I/flutter (16052): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#ca67f relayoutBoundary=up5 NEEDS-PAINT
I/flutter (16052): Another exception was thrown: RenderBox was not laid out: _RenderInkFeatures#a2ca4 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (16052): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#b4d9b relayoutBoundary=up3 NEEDS-PAINT
I/flutter (16052): Another exception was thrown: RenderBox was not laid out: RenderPhysicalShape#235a2 relayoutBoundary=up2 NEEDS-PAINT
I/flutter (16052): Another exception was thrown: 'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 314 pos 12: 'child.hasSize': is not true.
I/flutter (16052): Another exception was thrown: RenderBox was not laid out: RenderPhysicalShape#235a2 relayoutBoundary=up2
If there's a better way to do this, I'm open to it as long as the dialog won't resize.
UPDATE:
Here's a minimal sample, simply launch the following dialog:
AlertDialog(
content: PageView(
children: <Widget> [
Text('child1'),
Text('child2'),
Text('child3'),
],
),
);
The problem appears that PageView doesn't instantiate all the views right away but does it lazily to save CPU cycles. This means that AlertDialog can't size itself. I'm trying to figure out if there's a way to override PageView's default behavior and have it measure its size right away maybe?
UPDATE:
While I haven't been able to do anything with PageView I've been able to mimic the behavior I want with a simple IndexedStack. It just lacks the animations when programmatically moving between pages, but hopefully I'll be able to add that in. I'll post a final answer once finished.
Just wrap your PageView with a Container and specify its width and height will do the work.
AlertDialog(
Container(
width: width,
height: height,
child: PageView(
...
),
),
)