So In my app, there are three screens which can be navigated using a bottom bar, now for each of the three screens I want to display different navigation Tab bar but the same appBar,
what I tried is to use index of the list which contains elements of bottom bar and then returns a tabBar widget for each index but I end up with an error MyAppState is a SingleTickerProviderStateMixin but multiple tickers were created. and I have no idea what it is!
I really need to fix this please guide me with the sol or suggest if there is any other way to achieve this.
main.dart
import 'package:flutter/material.dart';
import 'journal/view/journal_lists.dart';
import 'todo/view/master_list.dart';
import 'mood_checker/view/mood.dart';
import 'journal/view/journal.dart';
Color primary = Color(0xFF3366FF);
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Mentor101',
home: MyApp(),
theme: ThemeData(
primaryColor: primary,
fontFamily: 'Poppins',
textTheme: TextTheme(
headline: TextStyle(
fontSize: 36, fontWeight: FontWeight.w600, color: Colors.white),
)),
));
}
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
//for bottom tab
int currentIndex = 0;
final _screens = [Journal(), MasterList(), MoodChecker()];
// for Tab Bar
TabController todoTabCon;
TabController moodTabCon;
TabController journalTabCon;
#override
void initState() {
super.initState();
todoTabCon = TabController(vsync: this, length: 3);
moodTabCon = TabController(vsync: this, length: 2);
journalTabCon = TabController(vsync: this, length: 2);
}
#override
void dispose() {
todoTabCon.dispose();
moodTabCon.dispose();
journalTabCon.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: myAppBar(context, 'ProApp'),
drawer: mainDrawer(context),
body: mainBody(),
bottomNavigationBar: myBottomBar(),
);
}
// ---------------------------------APP BAR STARTS-------------------------------//
Widget myAppBar(BuildContext context, String title) {
return AppBar(
centerTitle: true,
title: Text(
title,
style: Theme.of(context).textTheme.headline,
),
backgroundColor: Theme.of(context).primaryColor,
bottom: getTabBar(),
);
}
// ---------------------------------APP BAR ENDS-------------------------------//
// The problematic code
// to get a tabBar for different screens
Widget getTabBar() {
switch (currentIndex) {
case 0:
return journalTabBar();
break;
case 1:
return todoTabBar();
break;
case 2:
return moodTabBar();
break;
default:
}
}
//------------------------Tab Bars--------------------------//
Widget todoTabBar() {
return TabBar(
controller: todoTabCon,
tabs: <Widget>[
Tab(child: Text('MasterList')),
Tab(child: Text('DailyList')),
Tab(child: Text('MonthlyList')),
],
);
}
Widget moodTabBar() {
return TabBar(
controller: moodTabCon,
tabs: <Widget>[
Tab(child: Text('Checker')),
Tab(child: Text('Review')),
],
);
}
Widget journalTabBar() {
return TabBar(
controller: journalTabCon,
tabs: <Widget>[
Tab(child: Text('Journal')),
Tab(child: Text('Entries List')),
],
);
}
// ------------------------------Bottom BAR STARTS-------------------------------//
Widget myBottomBar() {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
fixedColor: primary,
currentIndex: currentIndex,
onTap: _onitemTapped,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.book), title: Text('Journal')),
BottomNavigationBarItem(
icon: Icon(Icons.view_list), title: Text('Todos')),
BottomNavigationBarItem(icon: Icon(Icons.mood), title: Text('Chart')),
],
);
}
void _onitemTapped(int index) {
setState(() {
currentIndex = index;
});
}
//Body starts----------
Widget mainBody() {
return _screens.elementAt(currentIndex);
}
// Body Ends---------
Error
(have to cut some part from the bottom due to StackOverflow body length limit(3000 words)
I/flutter (20666): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (20666): The following assertion was thrown building Builder:
I/flutter (20666): _MyAppState is a SingleTickerProviderStateMixin but multiple tickers were created.
I/flutter (20666): A SingleTickerProviderStateMixin can only be used as a TickerProvider once. If a State is used for
I/flutter (20666): multiple AnimationController objects, or if it is passed to other objects and those objects might
I/flutter (20666): use it more than one time in total, then instead of mixing in a SingleTickerProviderStateMixin, use
I/flutter (20666): a regular TickerProviderStateMixin.
I/flutter (20666):
I/flutter (20666): When the exception was thrown, this was the stack:
I/flutter (20666): #0 __MyAppState&State&SingleTickerProviderStateMixin.createTicker.<anonymous closure> (package:flutter/src/widgets/ticker_provider.dart:85:7)
I/flutter (20666): #1 __MyAppState&State&SingleTickerProviderStateMixin.createTicker (package:flutter/src/widgets/ticker_provider.dart:92:6)
I/flutter (20666): #2 new AnimationController (package:flutter/src/animation/animation_controller.dart:244:21)
I/flutter (20666): #3 new TabController (package:flutter/src/material/tab_controller.dart:86:50)
I/flutter (20666): #4 _MyAppState.initState (package:pro_app/main.dart:46:18)
I/flutter (20666): #5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3846:58)
I/flutter (20666): #6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #8 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #9 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #18 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #21 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #22 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #24 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #27 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #28 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #29 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #30 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #31 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #32 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #33 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter (20666): #34 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #38 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #40 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #41 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #42 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #43 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #44 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #45 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #46 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter (20666): #47 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #48 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #49 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #50 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #51 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #52 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #53 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #54 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #55 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #56 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #57 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #58 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #59 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #60 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #61 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #62 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #63 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #64 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #65 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter (20666): #66 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #67 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #68 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #69 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #70 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #71 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #72 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #73 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #74 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #75 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
I/flutter (20666): #76 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #77 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #78 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #79 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #80 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #81 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #82 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #83 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #84 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (20666): #85 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (20666): #86 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
I/flutter (20666): #87 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
I/flutter (20666): #88 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
I/flutter (20666): #89 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
I/flutter (20666): #90 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
I/flutter (20666): #91 ComponentElement.performRebuild...
One of the correct ways to create tabs would be specifying your routes in your main.dart, like this:
void main() {
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new Home(),
routes: <String, WidgetBuilder>{
"/tabs": (BuildContext context) => new Tabs(),//add your route
Now you need to create your tabs.dart file, with the corresponding Class Tabs(), as the following:
import 'package:YOURPROYECT/FOLDER/file.dart' as first; //here is your 1st tab
import 'package:YOURPROYECT/FOLDER/file.dart' as second;//and your second
//you can add more tabs, as third or fouth, see UI/UX what they recommend.
class Tabs extends StatefulWidget {
#override
MyTabsState createState() => new MyTabsState();
}
class MyTabsState extends State<Tabs> with SingleTickerProviderStateMixin {
TabController controller;
#override
Widget build(BuildContext context) {
return new Scaffold(
bottomNavigationBar: new Material(
color: color_appbar,
child: new TabBar(
controller: controller,
tabs: <Tab>[
new Tab(icon: new Icon(Icons.home,)),
new Tab(icon: new Icon(Icons.search)),
new Tab(icon: new Icon(Icons.notifications)),
]
)
),
body: new TabBarView(
controller: controller,
children: <Widget>[
new first.Home(),
new second.Search(),
new fourth.Notifications(),
new FutureBuilder(
//you can continous with you code
You must create a file for each tab, with the corresponding class,
for example for the Search() Class you can start like this.
import 'package:YOURPROYECT/Estilo.dart';
import 'package:flutter/material.dart';
class Search extends StatelessWidget {
#override
Widget build(BuildContext context){
return new Scaffold(
appBar: new AppBar(
title: new Text("Search"),
//you can continous
I hope I helped you.
Related
Edit: The answer is you need to either give a specific height or set the ListView shrinkWrap property true, without it the listView has an unbounded height and that's why the render library gives an exception.
I'm trying to nest ListView but unfortunately, I'm getting EXCEPTION by RENDER LIBRARY. I tried multiple ways of nesting ListViews from existing references, but all I did was confused my self.
Here is the concept design of the app as you can see. I am trying to add new listview.builder for genres and cast and then buttons.
Image of concept design
Image of Code
Gist link to file:
https://gist.github.com/purplecandy/279364f2a229ee3120a4b7474123dba9
Actually I was getting different types of error :/ as I was trying different implementation of it. This is from the current implementation
I/flutter ( 2244): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 2244): The following assertion was thrown during performLayout():
I/flutter ( 2244): 'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1598 pos 16:
I/flutter ( 2244): 'constraints.hasBoundedHeight': is not true.
I/flutter ( 2244):
I/flutter ( 2244): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 2244): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 2244): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 2244): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 2244):
I/flutter ( 2244): When the exception was thrown, this was the stack:
I/flutter ( 2244): #2 RenderShrinkWrappingViewport.performLayout (package:flutter/src/rendering/viewport.dart:1598:16)
I/flutter ( 2244): #3 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #4 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #5 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #6 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #7 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #8 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #9 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #10 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #11 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #12 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #13 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #14 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #15 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #16 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #17 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #18 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #19 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #20 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
I/flutter ( 2244): #21 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #22 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #23 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #24 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #25 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #26 RenderSliverMultiBoxAdaptor.insertAndLayoutChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:404:13)
I/flutter ( 2244): #27 RenderSliverList.performLayout.advance (package:flutter/src/rendering/sliver_list.dart:190:19)
I/flutter ( 2244): #28 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:233:19)
I/flutter ( 2244): #29 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #30 RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
I/flutter ( 2244): #31 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #32 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:405:13)
I/flutter ( 2244): #33 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1316:12)
I/flutter ( 2244): #34 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1234:20)
I/flutter ( 2244): #35 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #36 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #37 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #38 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #39 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #40 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #41 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #42 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #43 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #44 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #45 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #46 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #47 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #48 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #49 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #50 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #51 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #52 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
I/flutter ( 2244): #53 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
I/flutter ( 2244): #54 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter ( 2244): #55 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter ( 2244): #56 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #57 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #58 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #59 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #60 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1188:11)
I/flutter ( 2244): #61 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #62 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #63 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #64 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #65 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #66 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #67 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #68 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #69 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #70 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #71 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #72 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #73 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #74 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 2244): #75 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #76 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2879:14)
I/flutter ( 2244): #77 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 2244): #78 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter ( 2244): #79 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
I/flutter ( 2244): #80 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
I/flutter ( 2244): #81 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
I/flutter ( 2244): #82 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:677:13)
I/flutter ( 2244): #83 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter ( 2244): #84 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 2244): #85 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 2244): #86 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 2244): #87 _invoke (dart:ui/hooks.dart:154:13)
I/flutter ( 2244): #88 _drawFrame (dart:ui/hooks.dart:143:3)
I/flutter ( 2244): (elided 2 frames from class _AssertionError)
I/flutter ( 2244):
I/flutter ( 2244): The following RenderObject was being processed when the exception was fired:
I/flutter ( 2244): RenderShrinkWrappingViewport#9e743 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2244): creator: ShrinkWrappingViewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#75473] ← Semantics ←
I/flutter ( 2244): Listener ← _GestureSemantics ←
I/flutter ( 2244): RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#a81bd] ←
I/flutter ( 2244): _ScrollSemantics-[GlobalKey#aa93a] ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←
I/flutter ( 2244): NotificationListener<ScrollNotification> ← ⋯
I/flutter ( 2244): parentData: <none> (can use size)
I/flutter ( 2244): constraints: BoxConstraints(0.0<=w<=391.4, 0.0<=h<=Infinity)
I/flutter ( 2244): size: MISSING
I/flutter ( 2244): axisDirection: right
I/flutter ( 2244): crossAxisDirection: down
I/flutter ( 2244): offset: ScrollPositionWithSingleContext#2a8f7(offset: 0.0, range: null..null, viewport: null,
I/flutter ( 2244): ScrollableState, ClampingScrollPhysics, IdleScrollActivity#ff81b, ScrollDirection.idle)
I/flutter ( 2244): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 2244): RenderSliverPadding#c485f NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2244): RenderSliverList#1516b NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2244): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderShrinkWrappingViewport#9e743 relayoutBoundary=up14 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#b0d15 relayoutBoundary=up13 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#110a1 relayoutBoundary=up12 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#52bac relayoutBoundary=up11 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#f37d1 relayoutBoundary=up10 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#3b8cd relayoutBoundary=up9 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#08271 relayoutBoundary=up8 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#8d178 relayoutBoundary=up7 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#ef2c5 relayoutBoundary=up6 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderFlex#e3d23 relayoutBoundary=up5 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#093a9 relayoutBoundary=up4 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 461 pos 12: 'child.hasSize': is not true.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The getter 'scrollOffsetCorrection' was called on null.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
I/flutter ( 2244): GET requested properly
I/flutter ( 2244): Another exception was thrown: RenderBox was not laid out: RenderIndexedSemantics#3afa7 relayoutBoundary=up3 NEEDS-PAINT
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The getter 'scrollOffsetCorrection' was called on null.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
I/flutter ( 2244): Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 1578 pos 12: '!_debugDoingThisLayout': is not true.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The getter 'scrollOffsetCorrection' was called on null.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter ( 2244): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
Put your ListView.builder inside a Widget with a defined height.
Example:
Container(
height: double.maxFinite,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: 6,
itemBuilder: (BuildContext context, int index) {
return Text(
'${index}',
style:
TextStyle(color: Colors.white, fontSize: 146),
);
},
)
),
You have to make sure your horizontal ListView is within some sort of heighted Widget like a Container:
class HomePage extends StatefulWidget {
#override
State createState() => HomePageState();
}
class HomePageState extends State<HomePage> with TickerProviderStateMixin {
List<Widget> boxes = [];
#override
void initState() {
boxes.add(
Container(
width: 150.0,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.red),
),
),
);
boxes.add(
Container(
width: 150.0,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.green),
),
),
);
boxes.add(
Container(
width: 150.0,
child: Container(
decoration: BoxDecoration(color: Colors.blue),
),
),
);
boxes.add(
Container(
width: 150.0,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.orange),
),
),
);
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Material(
child: Column(children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
Container(
height: 200.0,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.red),
),
),
Container(
height: 200.0,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.green),
),
),
Container(
height: 200.0,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.blue),
),
),
Container(
height: 200.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: boxes.length,
itemBuilder: (context, int index) {
return boxes[index];
},
),
),
Container(
height: 200.0,
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.orange),
),
),
],
))
])),
);
}
}
I'm trying to create a DropdownButton with the names from local json file... I am using futurebuilder to do so.. I am getting the error
From my debugging trials I've understood that its because of a calling on null...
body: Container(
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(20.0),
child: FutureBuilder(
future: DefaultAssetBundle
.of(context)
.loadString('data_json/quran.json'),
builder: (BuildContext context, AsyncSnapshot snapshot){
var myData = json.decode(snapshot.data.toString());
if(snapshot.hasData){
list_Drop =
List<DropdownMenuItem<String>>.generate(myData.length, (int index){
print("=============="+myData[index]['name_simple']);
DropdownMenuItem(
value: myData[index]['name_simple'],
child : Text(myData[index]['name_simple']),
);
});
return DropdownButton(
isExpanded: true,
value: selected,
items: list_Drop,
onChanged: (value){
print("on Cchange");
selected = value;
return widget.storage.writeSelected(selected);
},
);
// return Text("Hellooooo not null");
}else{
return Text("Hellooooo its null");
}
}
)
I/flutter (28709): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (28709): The following NoSuchMethodError was thrown building FutureBuilder<String>(state:
I/flutter (28709): _FutureBuilderState<String>#aa30d):
I/flutter (28709): The getter 'value' was called on null.
I/flutter (28709): Receiver: null
I/flutter (28709): Tried calling: value
I/flutter (28709):
I/flutter (28709): When the exception was thrown, this was the stack:
I/flutter (28709): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (28709): #1 _DropdownButtonState._updateSelectedIndex (package:flutter/src/material/dropdown.dart:619:35)
I/flutter (28709): #2 _DropdownButtonState.initState (package:flutter/src/material/dropdown.dart:581:5)
I/flutter (28709): #3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3830:58)
I/flutter (28709): #4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (28709): #5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (28709): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (28709): #7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (28709): #8 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (28709): #9 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (28709): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (28709): #11 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (28709): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (28709): #13 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (28709): #14 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (28709): #15 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (28709): #16 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (28709): #17 StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
I/flutter (28709): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (28709): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (28709): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (28709): #21 ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (28709): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (28709): #23 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (28709): #24 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (28709): #25 ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (28709): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (28709): #27 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4585:32)
Please help me understand this error.
I am expecting the drop-down button to list all the names from the JSON file.
I think you need to return the DropdownMenuItem from within the generator of the List.generate constructor:
var myData = json.decode(snapshot.data.toString());
if(snapshot.hasData){
return DropdownButton(
isExpanded: true,
value: selected,
items: List<DropdownMenuItem<String>>.generate(myData.length, (int index) {
final nameSimple = myData[index]['name_simple'];
return DropdownMenuItem(
value: nameSimple,
child : Text(nameSimple),
);
}),
onChanged: (value){
print("on Cchange");
selected = value;
return widget.storage.writeSelected(selected);
},
);
}
This is my code for setting the Background Image of my app.
import 'package:flutter/material.dart';
void main() => runApp(Calculator());
class Calculator extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/Background_1.jpg"),
fit: BoxFit.cover,
),
),
child: null,
),
);
}
}
And this is the error I am getting when I am trying to run the code!
> I/flutter (10809): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
> ╞═══════════════════════════════════════════════════════════ I/flutter
> (10809): The following assertion was thrown building Calculator:
> I/flutter (10809): MediaQuery.of() called with a context that does not
> contain a MediaQuery. I/flutter (10809): No MediaQuery ancestor could
> be found starting from the context that was passed to MediaQuery.of().
> I/flutter (10809): This can happen because you do not have a
> WidgetsApp or MaterialApp widget (those widgets introduce I/flutter
> (10809): a MediaQuery), or it can happen if the context you use comes
> from a widget above those widgets. I/flutter (10809): The context used
> was: I/flutter (10809): Scaffold(dirty, state:
> ScaffoldState#0495a(lifecycle state: initialized, tickers: tracking 1
> I/flutter (10809): ticker)) I/flutter (10809): I/flutter (10809):
> When the exception was thrown, this was the stack: I/flutter (10809):
> #0 MediaQuery.of (package:flutter/src/widgets/media_query.dart:481:5) I/flutter
> (10809): #1 ScaffoldState.didChangeDependencies
> (package:flutter/src/material/scaffold.dart:1449:50) I/flutter
> (10809): #2 StatefulElement._firstBuild
> (package:flutter/src/widgets/framework.dart:3846:12) I/flutter
> (10809): #3 ComponentElement.mount
> (package:flutter/src/widgets/framework.dart:3696:5) I/flutter (10809):
> #4 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14) I/flutter
> (10809): #5 Element.updateChild
> (package:flutter/src/widgets/framework.dart:2753:12) I/flutter
> (10809): #6 ComponentElement.performRebuild
> (package:flutter/src/widgets/framework.dart:3732:16) I/flutter
> (10809): #7 Element.rebuild
> (package:flutter/src/widgets/framework.dart:3547:5) I/flutter (10809):
> #8 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5) I/flutter (10809):
> #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5) I/flutter (10809):
> #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14) I/flutter
> (10809): #11 Element.updateChild
> (package:flutter/src/widgets/framework.dart:2753:12) I/flutter
> (10809): #12 RenderObjectToWidgetElement._rebuild
> (package:flutter/src/widgets/binding.dart:909:16) I/flutter (10809):
> #13 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:880:5) I/flutter (10809):
> #14 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:826:17) I/flutter
> (10809): #15 BuildOwner.buildScope
> (package:flutter/src/widgets/framework.dart:2266:19) I/flutter
> (10809): #16 RenderObjectToWidgetAdapter.attachToRenderTree
> (package:flutter/src/widgets/binding.dart:825:13) I/flutter (10809):
> #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget
> (package:flutter/src/widgets/binding.dart:712:7) I/flutter (10809):
> #18 runApp (package:flutter/src/widgets/binding.dart:756:7) I/flutter (10809): #19 main (package:calculator/main.dart:3:16)
> I/flutter (10809): #20 _startIsolate.<anonymous closure>
> (dart:isolate/runtime/libisolate_patch.dart:289:19) I/flutter (10809):
> #21 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12) I/flutter (10809):
> ════════════════════════════════════════════════════════════════════════════════════════════════════
In the pubspec.yaml file, I have specified the asset as well with proper indentation, but nothing is of any help!
You need to wrap your Scaffold inside a WidgetsApp widget such as MaterialApp which creates its own MediaQuery:
class Calculator extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: new Scaffold(
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/Background_1.jpg"),
fit: BoxFit.cover,
),
),
child: null,
),
),
);
}
}
This code will give you a responsive background.
get a ref to you screen height and width from the BuildContext
to give your image size simply pass in the dimensions to your container.
I have demonstrated this below.
note* You no longer have to use the new keyword in Dart
import 'package:flutter/material.dart';
void main() => runApp(Calculator());
class Calculator extends StatelessWidget {
#override
Widget build(BuildContext context) {
//take a reference to width and height using the current context
var width = MediaQuery.of(context).size.width;
var height = MediaQuery.of(context).size.height;
return new Scaffold(
body: new Container(
//give the container the size and width
width:width,
height:height,
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/Background_1.jpg"),
fit: BoxFit.cover,
),
),
//Don't return null flutter doesn't allow it, You can use empty Container
as a place holder to avoid errors.
child: Container(),
),
);
}
}
i have been trying to trigger a dialog-box when the iconButton is click in appBar but error is coming
this error is persistance.
I think that the context passed in the showDialog() have some issue i'm not sure
import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
## Heading ##
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return _MyPortfolioState();
}
}
class _MyPortfolioState extends State<MyApp> {
MaterialColor primaryColor = Colors.blue;
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Portfolio',
theme: new ThemeData(
primarySwatch: primaryColor,
),
home: Scaffold(
appBar: AppBar(
title: Text("Dhruv Agarwal"),
textTheme: TextTheme(
display2: TextStyle(color: Color.fromARGB(1, 0, 0, 0))),
actions: <Widget>[
new IconButton(
icon: Icon(Icons.format_color_text),
tooltip: 'Change Color',
onPressed: () {
Color pickerColor = primaryColor;
changeColor(Color color) {
setState(() => primaryColor = color);
}
showDialog (
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Pick a color!'),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: pickerColor,
onColorChanged: changeColor,
pickerAreaHeightPercent: 0.8,
),
),
actions: <Widget>[
FlatButton(
child: Text('Got it'),
onPressed: () {
setState(() => primaryColor = pickerColor);
Navigator.of(context).pop();
},
),
],
);
});
},
),
])));
}
}
//
//
The exception is thrown on reload that No MaterialLocalizations found.
Launching lib/main.dart on Redmi Note 5 Pro in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
I/zygote64(16669): Do partial code cache collection, code=28KB, data=20KB
I/zygote64(16669): After code cache collection, code=28KB, data=20KB
I/zygote64(16669): Increasing code cache capacity to 128KB
Syncing files to device Redmi Note 5 Pro...
I/flutter (16669): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (16669): The following assertion was thrown while handling a gesture:
I/flutter (16669): No MaterialLocalizations found.
I/flutter (16669): MyApp widgets require MaterialLocalizations to be provided by a Localizations widget ancestor.
I/flutter (16669): Localizations are used to generate many different messages, labels,and abbreviations which are used
I/flutter (16669): by the material library.
I/flutter (16669): To introduce a MaterialLocalizations, either use a MaterialApp at the root of your application to
I/flutter (16669): include them automatically, or add a Localization widget with a MaterialLocalizations delegate.
I/flutter (16669): The specific widget that could not find a MaterialLocalizations ancestor was:
I/flutter (16669): MyApp
I/flutter (16669): The ancestors of this widget were:
I/flutter (16669): [root]
I/flutter (16669):
I/flutter (16669): When the exception was thrown, this was the stack:
I/flutter (16669): #0 debugCheckHasMaterialLocalizations.<anonymous closure> (package:flutter/src/material/debug.dart:124:7)
I/flutter (16669): #1 debugCheckHasMaterialLocalizations (package:flutter/src/material/debug.dart:127:4)
I/flutter (16669): #2 showDialog (package:flutter/src/material/dialog.dart:606:10)
I/flutter (16669): #3 MyApp.build.<anonymous closure> (file:///home/punisher/AndroidStudioProjects/first_app/portfolio/lib/main.dart:32:19)
I/flutter (16669): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
I/flutter (16669): #5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
I/flutter (16669): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
I/flutter (16669): #7 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
I/flutter (16669): #8 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
I/flutter (16669): #9 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
I/flutter (16669): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
I/flutter (16669): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
I/flutter (16669): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
I/flutter (16669): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
I/flutter (16669): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
I/flutter (16669): #15 _invoke1 (dart:ui/hooks.dart:153:13)
I/flutter (16669): #16 _dispatchPointerDataPacket (dart:ui/hooks.dart:107:5)
I/flutter (16669):
I/flutter (16669): Handler: onTap
I/flutter (16669): Recognizer:
I/flutter (16669): TapGestureRecognizer#5070d(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
I/flutter (16669): Offset(354.2, 64.0), sent tap down)
I/flutter (16669): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (16669): Another exception was thrown: No MaterialLocalizations found.
Some Material Widget in your tree requires localization to be set, so instead of running directly your app from a StatefulWidget, wrap it in a MaterialApp. So the MaterialApp will have your Widget as its child, and not the contrary.
main() => runApp(
MaterialApp(
title: 'ColorPicker test',
home: MyApp(),
),
);
The MaterialApp will setup the MaterialLocalizations in the widget tree and its children will be able to use it.
By the way, your code won't work as the ColorPicker chooses from all possible colors and the primarySwatch can only be MaterialColors. You can try again using a material ColorPicker. I think this plugin also provides it, you can check this one too.
I'm trying to create a form for my app containing two columns inside a row. Should look something like this:
But when I run this code:
#override
Widget build(BuildContext context) {
return /*new Padding (
padding: const EdgeInsets.all(15.0),
child: */new ListView (
//mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[new Row (children: <Widget>[
// Goal + Amount
new ListTile (
title: new Column (
mainAxisSize: MainAxisSize.min,
children: <Widget>[new Expanded(child: new TextField(
controller: widget._NameController,
style: new TextStyle (
fontSize: 20.0,
color: Colors.black,
),
decoration: new InputDecoration(
labelText: 'Name'
),
)), new Expanded(child:
new FlatButton(
onPressed: _showDatePicker,
child: new Text(
PARTIAL_DATE_FORMAT.format(_pickedDate)),
)),
]
)
),
// Goal Deadline
new ListTile (
title: new Column (
mainAxisSize: MainAxisSize.min,
children: <Widget>[new Expanded(child: new ListTile (
title: new TextField(
//controller: widget._TextController,,
style: new TextStyle (
fontSize: 20.0,
color: Colors.black
),
decoration: new InputDecoration(
labelText: 'Amount'
),
)
)), new Expanded(child:
new FlatButton(
onPressed: _showTimePicker,
child: new Text(_pickedTime.format(context)),
)),
]
)
),
]),
// Goal Description
new ListTile (
title: new TextField(
controller: widget._DescriptionController,
style: new TextStyle (
fontSize: 20.0,
color: Colors.black
),
decoration: new InputDecoration(
labelText: 'Description'
),
)
),
]
);
}
It resolves in this error:
I/flutter ( 2837): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 2837): The following assertion was thrown during performLayout():
I/flutter ( 2837): RenderFlex children have non-zero flex but incoming width constraints are unbounded.
I/flutter ( 2837): When a row is in a parent that does not provide a finite width constraint, for example if it is in a
I/flutter ( 2837): horizontal scrollable, it will try to shrink-wrap its children along the horizontal axis. Setting a
I/flutter ( 2837): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter ( 2837): space in the horizontal direction.
I/flutter ( 2837): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter ( 2837): cannot simultaneously expand to fit its parent.
I/flutter ( 2837): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter ( 2837): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter ( 2837): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter ( 2837): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter ( 2837): constraints provided by the parent.
I/flutter ( 2837): The affected RenderFlex is:
I/flutter ( 2837): RenderFlex#770e0 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): The creator information is set to:
I/flutter ( 2837): Row ← Padding ← ConstrainedBox ← Container ← Listener ← _GestureSemantics ← RawGestureDetector ←
I/flutter ( 2837): GestureDetector ← InkWell ← ListTile ← Row ← RepaintBoundary-[<0>] ← ⋯
I/flutter ( 2837): The nearest ancestor providing an unbounded width constraint is:
I/flutter ( 2837): RenderFlex#47431 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): creator: Row ← RepaintBoundary-[<0>] ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
I/flutter ( 2837): AutomaticKeepAlive ← SliverList ← Viewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#60f18] ←
I/flutter ( 2837): Listener ← _GestureSemantics ←
I/flutter ( 2837): RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#f4728] ← ⋯
I/flutter ( 2837): parentData: <none> (can use size)
I/flutter ( 2837): constraints: BoxConstraints(w=381.4, 0.0<=h<=Infinity)
I/flutter ( 2837): size: MISSING
I/flutter ( 2837): direction: horizontal
I/flutter ( 2837): mainAxisAlignment: start
I/flutter ( 2837): mainAxisSize: max
I/flutter ( 2837): crossAxisAlignment: center
I/flutter ( 2837): textDirection: ltr
I/flutter ( 2837): verticalDirection: downSee also: https://flutter.io/layout/
I/flutter ( 2837): If this message did not help you determine the problem, consider using debugDumpRenderTree():
I/flutter ( 2837): https://flutter.io/debugging/#rendering-layer
I/flutter ( 2837): http://docs.flutter.io/flutter/rendering/debugDumpRenderTree.html
I/flutter ( 2837): If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
I/flutter ( 2837): https://github.com/flutter/flutter/issues/new
I/flutter ( 2837): When the exception was thrown, this was the stack:
I/flutter ( 2837): #0 RenderFlex.performLayout.<anonymous closure> (package:flutter/src/rendering/flex.dart:690:11)
I/flutter ( 2837): #1 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:711:10)
I/flutter ( 2837): #2 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #3 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:197:11)
I/flutter ( 2837): #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #5 RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:257:13)
I/flutter ( 2837): #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #7 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #9 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #11 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:737:15)
I/flutter ( 2837): #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #13 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #15 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:164:27)
I/flutter ( 2837): #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #17 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:286:13)
I/flutter ( 2837): #18 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:979:12)
I/flutter ( 2837): #19 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:903:20)
I/flutter ( 2837): #20 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #21 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #22 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #23 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #24 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #25 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #26 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #27 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #28 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #29 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #30 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #31 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #32 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #33 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:197:11)
I/flutter ( 2837): #34 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #35 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:124:11)
I/flutter ( 2837): #36 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:91:7)
I/flutter ( 2837): #37 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:194:7)
I/flutter ( 2837): #38 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:338:14)
I/flutter ( 2837): #39 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #40 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #41 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #42 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #43 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1005:24)
I/flutter ( 2837): #44 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #45 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #46 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #47 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #48 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #49 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #50 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #51 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2747:14)
I/flutter ( 2837): #52 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #53 RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:107:13)
I/flutter ( 2837): #54 RenderObject.layout (package:flutter/src/rendering/object.dart:1962:7)
I/flutter ( 2837): #55 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:466:15)
I/flutter ( 2837): #56 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1837:7)
I/flutter ( 2837): #57 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1126:18)
I/flutter ( 2837): #58 BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:262
:19)
I/flutter ( 2837): #59 BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/bin
ding.dart:581:22)
I/flutter ( 2837): #60 BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rende
ring/binding.dart:200:5)
I/flutter ( 2837): #61 BindingBase&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:713:15)
I/flutter ( 2837): #62 BindingBase&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:649:9)
I/flutter ( 2837): #63 _invoke (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:91)
I/flutter ( 2837): #64 _drawFrame (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:80)
I/flutter ( 2837): The following RenderObject was being processed when the exception was fired:
I/flutter ( 2837): RenderFlex#770e0 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): creator: Row ← Padding ← ConstrainedBox ← Container ← Listener ← _GestureSemantics ←
I/flutter ( 2837): RawGestureDetector ← GestureDetector ← InkWell ← ListTile ← Row ← RepaintBoundary-[<0>] ← ⋯
I/flutter ( 2837): parentData: offset=Offset(0.0, 0.0) (can use size)
I/flutter ( 2837): constraints: BoxConstraints(0.0<=w<=Infinity, h=56.0)
I/flutter ( 2837): size: MISSING
I/flutter ( 2837): direction: horizontal
I/flutter ( 2837): mainAxisAlignment: start
I/flutter ( 2837): mainAxisSize: max
I/flutter ( 2837): crossAxisAlignment: center
I/flutter ( 2837): textDirection: ltr
I/flutter ( 2837): verticalDirection: down
I/flutter ( 2837): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 2837): RenderFlex#5610b NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderSemanticsGestureHandler#6d25d NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderPointerListener#4eb7b NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderConstrainedBox#3d105 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderStack#f6a43 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderConstrainedBox#13bd4 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderSemanticsGestureHandler#905d0 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderPointerListener#ec2c3 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): RenderPadding#2b663 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 2837): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 2837): Another exception was thrown: 'package:flutter/src/rendering/box.dart': Failed assertion: line 1433 pos 12: 'hasSize': is not true.
I/flutter ( 2837): Another exception was thrown: 'package:flutter/src/rendering/box.dart': Failed assertion: line 1433 pos 12: 'hasSize': is not true.
I/flutter ( 2837): Another exception was thrown: 'package:flutter/src/rendering/box.dart': Failed assertion: line 1433 pos 12: 'hasSize': is not true.
I/flutter ( 2837): Another exception was thrown: 'package:flutter/src/rendering/box.dart': Failed assertion: line 1433 pos 12: 'hasSize': is not true.
I/flutter ( 2837): Another exception was thrown: 'package:flutter/src/rendering/box.dart': Failed assertion: line 1433 pos 12: 'hasSize': is not true.
I/flutter ( 2837): Another exception was thrown: 'package:flutter/src/rendering/box.dart': Failed assertion: line 1433 pos 12: 'hasSize': is not true.
I/flutter ( 2837): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 458 pos 12: 'child.hasSiz
e': is not true.
I/flutter ( 2837): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter ( 2837): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
I'm very new to flutter and having a lot of trouble working with it due to the lack of information on the internet about that.
I have a created a simple example to show you how you can approach building the desired layout, the usage of ListTile in your code is really confusing and should not be used in this way. The information you provided are not clear enough on what the different elements in your layout represents. That is why I am filling them with a Container, you should be able to provide any widget as child of the container to get started.
import "package:flutter/material.dart";
class Layout extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(),
body: new Padding(
padding: const EdgeInsets.all(30.0),
child:new Column(
children: <Widget>[
new Row(
children: <Widget>[
new SizedBox(
height: 30.0 ,
width: 200.0,
child: new Container(color: Colors.redAccent,),
),
new Container(width: 40.0,),
new SizedBox(
height: 30.0,
width: 50.0,
child: new Container(color:Colors.amberAccent),
)
],
),
new Container(height: 30.0,),
new Row(
children: <Widget>[
new SizedBox(
height: 40.0 ,
width: 100.0,
child: new Container(color: Colors.redAccent,),
),
new Container(width: 140.0,),
new SizedBox(
height: 40.0,
width: 50.0,
child: new Container(color:Colors.amberAccent),
)
],
),
new Container(height: 30.0,),
new Container(color: Colors.tealAccent,width: 290.0,height: 320.0,)
],
),),
);
}
}
Update
I believe you are trying to do similar layout to the following one, the real problem with your code is using ListTile, ListTiles are used to store minimal information (like contact lists for example), and should not be used to contain nested widgets because they are limited in size.
Secondly, I was only doing the previous example as a demonstration, however, yes you are correct about the fixed size problems. In order to avoid this you can use check FractionallySizedBox, or like I did at the very end of the ListView here, using MediaQuery.of(context).size.height*0.3 gave me a Container with height that is 30% of the total screen height.
import "package:flutter/material.dart";
class Layout extends StatefulWidget {
#override
_LayoutState createState() => new _LayoutState();
}
class _LayoutState extends State<Layout> {
String time = "Set Time";
String date = "Set Date ";
String dropDownString;
_showDate(BuildContext context) async {
var datePicked = await showDatePicker(context: context,
initialDate: new DateTime.now(),
firstDate: new DateTime(2010, 2),
lastDate: new DateTime(2018, 1));
setState(() {
date = "${datePicked.month}/${datePicked.day}/${datePicked.year}";
});
}
_showTime(BuildContext context) async {
var timePicked = await showTimePicker(
context: context, initialTime: new TimeOfDay.now());
setState(() {
time = "${timePicked.hour}:${timePicked.minute} ";
});
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Layout Example"),),
body: new Padding(padding: const EdgeInsets.all(20.0),
child: new ListView(
//shrinkWrap: true,
children: <Widget>[
new Row(
children: <Widget>[
new Expanded(child: new TextField()),
new Expanded(child: new FlatButton(
onPressed: () => _showDate(context),
child: new Text(date))),
],
),
new Row(
children: <Widget>[
new Expanded(child: new TextField()),
new Expanded(child: new FlatButton(
onPressed: () => _showTime(context),
child: new Text(time))),
],),
new TextField(
maxLines: 5,
),
new Container(
height: MediaQuery.of(context).size.height*0.3,
color: Colors.tealAccent,
)
],
),
),
);
}
}