Related
Hello when ever I tried to call the bottombar widget (the custom widget that I created) The other widget elements dissapears
here is the home_page.dart code:
import 'package:clothing_app/utils/bottom_bar.dart';
import 'package:flutter/material.dart';
import 'package:line_awesome_icons/line_awesome_icons.dart';
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int buttonSelected = 1;
#override
Widget build(BuildContext context) {
return Material(
child: Scaffold(
bottomNavigationBar: BottomBar(),
appBar: AppBar(
elevation: 0,
backgroundColor: SCAFFOLD_BG_COLOR,
leading: IconButton(
onPressed: () {},
icon: Icon(
LineAwesomeIcons.bars,
color: MAIN_BLACK_COLOR,
),
),
actions: <Widget>[
IconButton(
onPressed: () {},
icon: Icon(
LineAwesomeIcons.search,
color: MAIN_BLACK_COLOR,
),
),
],
),
body: Column(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
padding: EdgeInsets.symmetric(
vertical: 12, horizontal: 16),
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
_topSlideItem(),
SizedBox(
width: 24,
),
_topSlideItem(),
SizedBox(
width: 24,
),
_topSlideItem(),
SizedBox(
width: 24,
),
_topSlideItem(),
SizedBox(
width: 24,
),
_topSlideItem(),
SizedBox(
width: 24,
),
_topSlideItem(),
],
),
),
),
],
),
Padding(
padding:
EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Best of the week',
style: TextStyle(
fontSize: 22, fontWeight: FontWeight.bold),
),
SizedBox(
height: 24,
),
verticalSlideItem(),
SizedBox(height: 16),
verticalSlideItem(),
SizedBox(height: 16),
verticalSlideItem(),
SizedBox(height: 16),
verticalSlideItem(),
SizedBox(height: 16),
verticalSlideItem(),
SizedBox(height: 16),
verticalSlideItem(),
],
),
)
],
),
),
),
],
),
),
);
}
Widget _topSlideItem() {
return Material(
borderRadius: BorderRadius.circular(32),
color: Colors.white,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 32),
width: MediaQuery.of(context).size.width * .55,
child: Row(
children: <Widget>[
Image.asset(
'assets/img.jpeg',
height: 140,
width: 50,
fit: BoxFit.fitHeight,
),
SizedBox(width: 24),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Flower patterned khaki dress',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 12,
),
Row(
children: <Widget>[
Container(
height: 12,
width: 12,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(4),
),
),
SizedBox(
width: 8,
),
Container(
height: 12,
width: 12,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(4),
),
),
SizedBox(
width: 8,
),
Container(
height: 12,
width: 12,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(4),
),
)
],
),
SizedBox(
height: 12,
),
Text(
'\$89,99',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color.fromRGBO(180, 184, 190, 1),
),
),
],
),
)
],
),
),
);
}
Widget verticalSlideItem() {
return Material(
borderRadius: BorderRadius.circular(32),
color: Colors.transparent,
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(24)),
child: Center(
child: Image.asset(
'assets/img.jpeg',
height: 110,
width: 80,
fit: BoxFit.fitHeight,
),
),
),
SizedBox(width: 24),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Flower patterned\nkhaki dress',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 12,
),
Row(
children: <Widget>[
Container(
height: 12,
width: 12,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(4),
),
),
SizedBox(
width: 8,
),
Container(
height: 12,
width: 12,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(4),
),
),
SizedBox(
width: 8,
),
Container(
height: 12,
width: 12,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(4),
),
)
],
),
SizedBox(
height: 12,
),
Text(
'\$89,99',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color.fromRGBO(180, 184, 190, 1),
),
),
],
),
)
],
),
),
);
}
}
here is the custom widget I created (bottom_bar.dart);
#override
Widget build(BuildContext context) {
return Container(
child: Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.call),
label: 'Calls',
),
BottomNavigationBarItem(
icon: Icon(Icons.camera),
label: 'Camera',
),
BottomNavigationBarItem(
icon: Icon(Icons.chat),
label: 'Chats',
),
],
),
),
);
}
}
here is the main.dart file;
import 'package:flutter/material.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: 'Cera'),
home: HomePage(),
);
}
}
here is the image when I call the bottom navigationbar;
and here is an image when I remove the bottom navigationbar code line (bottomNavigationBar: BottomBar(),);
You are wrapping your custom BottomNavigationBar with Scaffold and it covers you HomePage Scaffold, so that's why the other widgets couldn't be shown.
Remove the Scaffold from the custom BottomNavigationBar:
#override
Widget build(BuildContext context) {
return BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.call),
label: 'Calls',
),
BottomNavigationBarItem(
icon: Icon(Icons.camera),
label: 'Camera',
),
BottomNavigationBarItem(
icon: Icon(Icons.chat),
label: 'Chats',
),
],
);
}
I am trying to display a container with some designs if it gets some data from firestore but if there is no data from firestore I want it to show a text saying no data from firestore, but it is not working and I'm getting errors.
...............................................................................................................................
below is the code, is this correct? getStoriesFunction:
Widget _getStories() {
Live users;
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: getStory(users),
);
}
Widget getStory(Live user) {
return Container(
margin: EdgeInsets.all(12),
child: Column(
children: <Widget>[
user.isLive == true
? Container(
height: 55,
width: 55,
child: GestureDetector(
onTap: () {
// Join function
onJoin(
channelName: user.displayName,
channelId: user.channelId,
displayName: displayName,
hostImage: user.image,
userImage: image);
},
child: Stack(
alignment: Alignment(0, 0),
children: <Widget>[
Container(
height: 60,
width: 60,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
Colors.red,
Colors.redAccent,
Colors.red
],
begin: Alignment.topLeft,
end: Alignment.bottomRight)),
),
),
Container(
height: 55.5,
width: 55.5,
child: CircleAvatar(
backgroundColor: Colors.black,
),
),
CachedNetworkImage(
imageUrl: user.image,
imageBuilder: (context, imageProvider) => Container(
width: 52.0,
height: 52.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: imageProvider, fit: BoxFit.cover),
),
),
),
Container(
height: 70,
width: 70,
alignment: Alignment.bottomCenter,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Container(
height: 17,
width: 25,
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(
Radius.circular(
4.0) // <--- border radius here
),
gradient: LinearGradient(
colors: [Colors.black, Colors.black],
begin: Alignment.centerLeft,
end: Alignment.centerRight),
),
),
Container(
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(
Radius.circular(
2.0) // <--- border radius here
),
gradient: LinearGradient(
colors: [
Colors.red,
Colors.redAccent
],
begin: Alignment.centerLeft,
end: Alignment.centerRight),
),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Text(
'LIVE',
style: TextStyle(
fontSize: 7,
color: Colors.white,
fontWeight: FontWeight.bold),
),
)),
],
))
],
),
))
: Text('No data in firestore',
style: TextStyle(
color: Colors.black,
fontSize: 12,
))
],
));
}
I have corrected you code and tested in the DartPad and work well for me. You can test to just copy and pase. It something wrong with user data from the firebase looks like bool isLive always true.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// Fake user data
bool userExist = false;
void _toggleUserState() {
setState(() => userExist = !userExist);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_getStories(userExist),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _toggleUserState,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _getStories(bool user) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: getStory(user),
);
}
Widget getStory(bool user) {
return Container(
margin: EdgeInsets.all(12),
child: user == true
? Column(
children: <Widget>[
Container(
height: 55,
width: 55,
child: GestureDetector(
onTap: () {
// Join function
print('Join Function');
},
child: Stack(
alignment: Alignment(0, 0),
children: <Widget>[
Container(
height: 60,
width: 60,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
Colors.red,
Colors.redAccent,
Colors.red
],
begin: Alignment.topLeft,
end: Alignment.bottomRight),
),
),
),
Container(
height: 55.5,
width: 55.5,
child: CircleAvatar(
backgroundColor: Colors.black,
),
),
// Cached Image container here.
Container(
height: 55.5,
width: 55.5,
child: Text('Cached Image'),
),
Container(
height: 70,
width: 70,
alignment: Alignment.bottomCenter,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Container(
height: 17,
width: 25,
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
gradient: LinearGradient(
colors: [Colors.black, Colors.black],
begin: Alignment.centerLeft,
end: Alignment.centerRight),
),
),
Container(
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular(2.0)),
gradient: LinearGradient(
colors: [Colors.red, Colors.redAccent],
begin: Alignment.centerLeft,
end: Alignment.centerRight),
),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Text(
'LIVE',
style: TextStyle(
fontSize: 7,
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
),
],
),
)
],
),
),
)
],
)
: Text(
'No data in firestore',
style: TextStyle(
color: Colors.black,
fontSize: 12,
),
),
);
}
}
I'm developing an app and was following a sample from this link and ran into a problem where it says bottom overflowed by xx pixels as shown below:
Now, I encountered this before and solved it by adding SingleChildScrollView as shown below:
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Academy',
theme: new ThemeData(
primaryColor: Color.fromRGBO(58, 66, 86, 1.0)
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: new Container(
child: SingleChildScrollView(
child: LoginScreen(),
)
),
),
);
}
How do I do it when I'm not using a container but a column instead ? As that is what I'm using in the image above (column at the bottom of code, where the author returns the scaffold):
class DetailPage extends StatelessWidget {
final Lesson lesson;
DetailPage({Key key, this.lesson}) : super(key: key);
#override
Widget build(BuildContext context) {
final levelIndicator = Container(
child: Container(
child: LinearProgressIndicator(
backgroundColor: Color.fromRGBO(209, 224, 224, 0.2),
value: lesson.indicatorValue,
valueColor: AlwaysStoppedAnimation(Colors.green)),
),
);
final coursePrice = Container(
padding: const EdgeInsets.all(7.0),
decoration: new BoxDecoration(
border: new Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(5.0)),
child: new Text(
"\$" + lesson.price.toString(),
style: TextStyle(color: Colors.white),
),
);
final topContentText = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 120.0),
Icon(
Icons.directions_car,
color: Colors.white,
size: 40.0,
),
Container(
width: 90.0,
child: new Divider(color: Colors.green),
),
SizedBox(height: 10.0),
Text(
lesson.title,
style: TextStyle(color: Colors.white, fontSize: 45.0),
),
SizedBox(height: 30.0),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(flex: 1, child: levelIndicator),
Expanded(
flex: 6,
child: Padding(
padding: EdgeInsets.only(left: 10.0),
child: Text(
lesson.level,
style: TextStyle(color: Colors.white),
))),
Expanded(flex: 1, child: coursePrice)
],
),
],
);
final topContent = Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 10.0),
height: MediaQuery.of(context).size.height * 0.5,
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/drones1.jpg"),
fit: BoxFit.cover,
),
)),
Container(
height: MediaQuery.of(context).size.height * 0.5,
padding: EdgeInsets.all(40.0),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, .9)),
child: Center(
child: topContentText,
),
),
Positioned(
left: 8.0,
top: 60.0,
child: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back, color: Colors.white),
),
)
],
);
final bottomContentText = Text(
lesson.content,
style: TextStyle(fontSize: 18.0),
);
final readButton = Container(
padding: EdgeInsets.symmetric(vertical: 16.0),
width: MediaQuery.of(context).size.width,
child: RaisedButton(
onPressed: () => {},
color: Color.fromRGBO(58, 66, 86, 1.0),
child:
Text("TAKE THIS LESSON", style: TextStyle(color: Colors.white)),
));
final bottomContent = Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(40.0),
child: Center(
child: Column(
children: <Widget>[bottomContentText, readButton],
),
),
);
return Scaffold(
body: Column( //here is the column
children: <Widget>[topContent, bottomContent],
),
);
}
}
I tried these but it does not work, giving me the same result as before:
return Scaffold(
body: Container(child: SingleChildScrollView(child:Column(children: <Widget>[topContent, bottomContent],),),),
);
return Scaffold(
body: Column(
children: <Widget>[Expanded(child: Column(children: <Widget>[topContent, bottomContent],))],
),
);
return Scaffold(
body: SingleChildScrollView(child: Container(child:Column(children: <Widget>[topContent, bottomContent],),),),
);
My outcome when I tried this as suggested:
return Scaffold(
body: Column( //here is the column
children: <Widget>[Expanded(child: SingleChildScrollView(child: Text("Test"))), Text("Data")],
),
);
I solved it by adding the SingleChildScrollView to the following in topContent:
Container(
height: MediaQuery.of(context).size.height * 0.5,
padding: EdgeInsets.all(40.0),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, .9)),
child: SingleChildScrollView(
child: Center(
child: topContentText,
),
),
),
I want to add expandable menu to drawer items of flutter. How can I achieve this functionality in flutter. Please just point me in the correct direction if there is any example or blog.
You have to pass the drawers child property a ListView, and in that ListView you can then use an ExpansionTile. That would look something like this:
Drawer(
child: ListView(
children: <Widget>[
ExpansionTile(
title: Text("Expansion Title"),
children: <Widget>[Text("children 1"), Text("children 2")],
)
],
),
);
You have to pass the drawers child property a ListView, and in that ListView you can then use an ExpansionTile. That would look something like this:
ExpansionTile(
title: Text('Categories'),
leading: Icon(Icons.view_list),
children: <Widget>[
GestureDetector(
child: SizedBox(
width: 250,
height: 35,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Shalwar kameez"))))),
onTap: (){},
),
SizedBox(height: 7,),
GestureDetector(
child: SizedBox(
width: 250,
height: 35,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Sherwani."))))),
onTap: (){},),
SizedBox(height: 7,),
GestureDetector(
child: SizedBox(
width: 250,
height: 35,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Sindhi Ajrak or Cap."))))),
onTap: (){},),
SizedBox(height: 7,),
GestureDetector(
child: SizedBox(
width:250,
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Punjabi kurta and tehmat."))))),
onTap: (){},),
SizedBox(height: 7,),
GestureDetector(
child: SizedBox(
width: 250,
height: 35,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Saraiki Turban"))))),
onTap: (){},),
SizedBox(height: 7,),
GestureDetector(
child: SizedBox(
width: 250,
height: 35,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Saraiki Kurta."))))),
onTap: (){},),
SizedBox(height: 7,),
GestureDetector(
child: SizedBox(
width: 250,
height: 35,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Peshawari Turban."))))),
onTap: (){},),
SizedBox(height: 7,),
GestureDetector(
child: SizedBox(
width: 250,
height: 35,
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(15),
),
child: Card(child: Center(child: Text("Lehenga Choli"))))),
onTap: (){},),
],
My solution:
ExpansionTile(
leading: Icon(
Icons.settings,
color: headingcolor,
),
trailing: Icon(
Icons.arrow_forward_ios_rounded,
size: 10.0,
color: defaultcolor,
),
title: Text(
"Settings",
style: TextStyle(
color: headingcolor,
),
),
children: <Widget>[
DrawerListTile(
title: "Terms",
svgSrc: Icon(
Icons.rule_sharp,
color: headingcolor,
),
press: () {
Get.offAll(
() => SettingsScreenMainTerms(),
duration: Duration(milliseconds: 400), //
transition: Transition.zoom,
);
},
),
DrawerListTile(
title: "Notifications",
svgSrc: Icon(
Icons.edit_notifications_rounded,
color: headingcolor,
),
press: () {
Get.offAll(
() => SettingsScreenMainNotifications(),
duration: Duration(milliseconds: 400), //
transition: Transition.zoom,
);
},
),
],
),
I am trying with the following code
class NewItemCreate extends StatefulWidget{
#override
NewItemCreateState createState() => new NewItemCreateState();
}
class NewItemCreateState extends State<NewItemCreate>
{
File _image;
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image = image;
});
print(_image.path);
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.yellow,
appBar: new AppBar(
title: new Text("Report"),
elevation: 5.0,
),
body:
Center (
child: ListView(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
shrinkWrap: true,
children: <Widget>[
itemImage,
SizedBox(height: 18.0),
itemName,
SizedBox(height: 18.0),
itemLocation,
SizedBox(height: 18.0),
itemLocation,
SizedBox(height: 18.0),
itemTime,
SizedBox(height: 18.0),
Report,
SizedBox(height: 38.0),
],
)
)
);
}
final itemImage = Padding(
padding: EdgeInsets.symmetric(vertical: 25.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.lightBlueAccent.shade100,
elevation: 5.0,
child: MaterialButton(
minWidth: 200.0,
height: 300.0,
onPressed: (){
getImage();
},
color: Colors.lightGreenAccent,
child:
new Icon(Icons.add_a_photo, size: 150.0,color: Colors.blue,),
),
),
);
There is already a question here,
Error: Only static members can be accessed in initializers what does this mean?
regarding this very issue, but, should I really be using "SingleTickerProviderStateMixin" for this? Also, is this something to do with singletons? (I am still learning programming)
Error after trying out the below answer:
final itemImage = ...
initializes a class-level field. This code is executed before the constructor is completed and the object fully initialized, therefore accessing this. (implicit or explicit) is forbidden because it can't be guaranteed that what you attempt to access is already initialized.
Creating and caching widgets this way is a bad idea in general anyway.
Instead make it a method:
Widget buildItemImage(BuildContext context) => Padding(
padding: EdgeInsets.symmetric(vertical: 25.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.lightBlueAccent.shade100,
elevation: 5.0,
child: MaterialButton(
minWidth: 200.0,
height: 300.0,
onPressed: () {
getImage();
},
color: Colors.lightGreenAccent,
child: new Icon(Icons.add_a_photo, size: 150.0,color: Colors.blue,
),
),
),
);
This way the code is first executed when buildItemImage(context) is called, not when the object instance is created. At this time it is guaranteed to be save to access this..
Try to cut the
Padding(
padding: EdgeInsets.symmetric(vertical: 25.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.lightBlueAccent.shade100,
elevation: 5.0,
child: MaterialButton(
minWidth: 200.0,
height: 300.0,
onPressed: (){
getImage();
},
color: Colors.lightGreenAccent,
child:
new Icon(Icons.add_a_photo, size: 150.0,color: Colors.blue,),
),
),
);
And paste it in children<Widget>[//here] and add a new
body:
Center (
child: ListView(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
shrinkWrap: true,
children: <Widget>[
------------/*there it is*/---------------------------
new Padding(
padding: EdgeInsets.symmetric(vertical: 25.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.lightBlueAccent.shade100,
elevation: 5.0,
child: MaterialButton(
minWidth: 200.0,
height: 300.0,
onPressed: (){
getImage();
},
color: Colors.lightGreenAccent,
child:
new Icon(Icons.add_a_photo, size: 150.0,color:
Colors.blue,),
),
),
-----------------------------------------------------
SizedBox(height: 18.0),
itemName,
SizedBox(height: 18.0),
itemLocation,
SizedBox(height: 18.0),
itemLocation,
SizedBox(height: 18.0),
itemTime,
SizedBox(height: 18.0),
Report,
SizedBox(height: 38.0),
],
)
)
Hope it's work :)