Exception caught by rendering library A RenderFlex overflowed by 98349 pixels on the right. The relevant error-causing widget was AppBar - flutter

[hello, i'm doing this site and impractical what happens, everything goes except the app bar (from another error that is index out of range index is 0) this site is connected to firebase, the problem i think is there just that i don't know how solve it mainly because I have looked a lot of times that the collections on firebase had the right names but still does not go does anyone have a solution?]
CollectionReference userCollectionReference =
FirebaseFirestore.instance.collection('users');
CollectionReference bookCollectionReference =
FirebaseFirestore.instance.collection('books');
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white24,
elevation: 0.0,
toolbarHeight: 77,
centerTitle: false,
title: Row(
children: [
Text(
'A.Reader',
style: Theme.of(context).textTheme.headline6.copyWith(
color: Colors.redAccent, fontWeight: FontWeight.bold),
),
],
),
actions: [
StreamBuilder<QuerySnapshot>(
stream: userCollectionReference.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
final userListStream = snapshot.data.docs.map((user) {
return MUser.fromDocument(user);
}).where((user) {
return (user.uid == FirebaseAuth.instance.currentUser.uid);
}).toList(); //[user]
MUser curUser = userListStream[0];
print(userListStream);
return Column(
children: [
SizedBox(
height: 40,
width: 40,
child: InkWell(
child: CircleAvatar(
radius: 60,
backgroundImage: NetworkImage(
/* curUser.avatarUrl != null
? curUser.avatarUrl
: */
'https://i.pravatar.cc/300'),
backgroundColor: Colors.white,
child: Text(''),
),
onTap: () {
showDialog(
context: context,
builder: (context) {
// return createProfileMobile(context, userListStream,
// FirebaseAuth.instance.currentUser, null);
return createProfileDialog(context, curUser);
},
);
},
),
),
Text(
curUser.displayName.toUpperCase(),
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Colors.black),
)
],
);
},
),
TextButton.icon(
onPressed: () {
FirebaseAuth.instance.signOut().then((value) {
return Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginPage(),
));
});
},
icon: Icon(Icons.logout),
label: Text(''))
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BookSearchPage(),
));
},
child: Icon(Icons.add),
backgroundColor: Colors.redAccent,
),
//error:
packages/flutter/src/widgets/async.dart 124:48 build
...
Exception caught by rendering library
A RenderFlex overflowed by 98349 pixels on the right.
The relevant error-causing widget was
AppBar
lib\screens\main_screen.dart:26

I think You Should write wrong code formatting try it out your code like below:
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white24,
elevation: 0.0,
toolbarHeight: 77,
centerTitle: false,
title: Text(
'A.Reader',
style: Theme.of(context).textTheme.headline6.copyWith(
color: Colors.redAccent, fontWeight: FontWeight.bold),
),
),
body:StreamBuilder<QuerySnapshot>(
stream: userCollectionReference.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
final userListStream = snapshot.data.docs.map((user) {
return MUser.fromDocument(user);
}).where((user) {
return (user.uid == FirebaseAuth.instance.currentUser.uid);
}).toList(); //[user]
MUser curUser = userListStream[0];
print(userListStream);
return Column(
children: [
SizedBox(
height: 40,
width: 40,
child: InkWell(
child: CircleAvatar(
radius: 60,
backgroundImage: NetworkImage(
/* curUser.avatarUrl != null
? curUser.avatarUrl
: */
'https://i.pravatar.cc/300'),
backgroundColor: Colors.white,
child: Text(''),
),
onTap: () {
showDialog(
context: context,
builder: (context) {
// return createProfileMobile(context, userListStream,
// FirebaseAuth.instance.currentUser, null);
return createProfileDialog(context, curUser);
},
);
},
),
),
Text(
curUser.displayName.toUpperCase(),
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Colors.black),
)
],
);
},
),
TextButton(
onPressed: () {
FirebaseAuth.instance.signOut().then((value) {
return Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginPage(),
));
});
},
icon: Icon(Icons.logout),
label: Text(''))
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BookSearchPage(),
));
},
child: Icon(Icons.add),
backgroundColor: Colors.redAccent,
));
remove your StreamBuilder inside action[] of appbar and add it to the body of scaffold

Related

Showing empty widget while FutureBuilder is loading data

I have the following FutureBuilder:
child: FutureBuilder(
future: fetchNotifications(widget.usuarioId),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<dynamic>? filteredList = snapshot.data as List;
return ListView.separated(
separatorBuilder: (BuildContext context, int index) =>
new Divider(
color: Colors.black26,
thickness: 0.5,
),
itemCount: filteredList.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, index) {
NotificationModelo notificacion = filteredList[index];
var textoNot = notificacion.texto;
print("texto ${notificacion.texto}");
if (notificacion.texto == "New files available for you" &&
_fr) {
textoNot = "Nouveaux fichiers disponibles pour vous";
}
if (_fr) {}
return GestureDetector(
onTap: () {},
child: Container(
height: 50,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: GestureDetector(
onTap: () {
if (notificacion.categoria == "Travel Document") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BDTravelDocumentsNuevo()));
}
if (notificacion.categoria == "Itinerary") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BDItineraryNuevo()));
}
if (notificacion.categoria == "Experience") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BDExperiencesNuevo()));
}
if (notificacion.categoria == "News and Promos") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
PrivateAreaNuevoDos()));
}
},
child: Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Card(
elevation: 0,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
width: MediaQuery.of(context).size.width,
child: Center(
child: new Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
SizedBox(
width: 10,
),
notificacion.categoria ==
"Travel Document"
? CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage(
"assets/item2.png"),
backgroundColor:
Colors.transparent,
)
: notificacion.categoria ==
"Itinerary"
? CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage(
"assets/item3.png"),
backgroundColor:
Colors.transparent,
)
: notificacion.categoria ==
"Experience"
? CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage(
"assets/item4.png"),
backgroundColor:
Colors.transparent,
)
: CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage(
"assets/logolc.png"),
backgroundColor:
Colors.transparent,
),
SizedBox(
width: 15,
),
Row(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Container(
width: 199,
height: 40,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
"${textoNot}",
textAlign: TextAlign.start,
maxLines: 1,
overflow:
TextOverflow.ellipsis,
style: TextStyle(
fontSize: 15,
fontWeight:
FontWeight.bold),
),
],
),
),
],
),
Spacer(),
GestureDetector(
onTap: () {},
child: notificacion.categoria ==
"Push"
? Container()
: IconButton(
onPressed: () {
if (notificacion
.categoria ==
"Travel Document") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BDTravelDocumentsNuevo()));
}
if (notificacion
.categoria ==
"Itinerary") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BDItineraryNuevo()));
}
if (notificacion
.categoria ==
"Experience") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
BDExperiencesNuevo()));
}
if (notificacion
.categoria ==
"News and Promos") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
PrivateAreaNuevoDos()));
}
},
icon: Icon(
Icons.arrow_forward_ios,
)),
)
],
),
),
),
)),
),
),
),
);
},
);
}
return AnyNotification();
}),
It is working as it should, the only issue is that I need to show the list data just after loading the data is finished, and now during loading time it is showing the widget AnyNotification(), which I want to show only when there are any data to show.
My customer doesn´t want to show anything during loading time.
You can follow this structure.
return FutureBuilder(
future: future,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
}
if (snapshot.hasError) {
return Text("got error");
}
if (snapshot.hasData) {
List<dynamic>? filteredList = snapshot.data as List?;
if (filteredList == null || filteredList.isEmpty) {
return AnyNotification();
} else {
return ListView.separated(
itemBuilder: itemBuilder,
separatorBuilder: separatorBuilder,
itemCount: itemCount,
);
}
}
return Text("NA State");
},
);
Find more about FutureBuilder-class.
Try the following code:
FutureBuilder(
future: fetchNotifications(widget.usuarioId),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
if (snapshot.hasError) {
return const Text("Error");
}
if (snapshot.hasData) {
List<dynamic>? filteredList = snapshot.data as List;
return ListView.separated(
separatorBuilder: (BuildContext context, int index) => const Divider(color: Colors.black26,thickness: 0.5),
itemCount: filteredList.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, index) {
NotificationModelo notificacion = filteredList[index];
var textoNot = notificacion.texto;
print("texto ${notificacion.texto}");
if (notificacion.texto == "New files available for you" && _fr) {
textoNot = "Nouveaux fichiers disponibles pour vous";
}
if (_fr) {}
return GestureDetector(
onTap: () {},
child: Container(
height: 50,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: GestureDetector(
onTap: () {
if (notificacion.categoria == "Travel Document") {
Navigator.push(context, MaterialPageRoute(builder: (context) => BDTravelDocumentsNuevo()));
}
if (notificacion.categoria == "Itinerary") {
Navigator.push(context, MaterialPageRoute(builder: (context) => BDItineraryNuevo()));
}
if (notificacion.categoria == "Experience") {
Navigator.push(context, MaterialPageRoute(builder: (context) => BDExperiencesNuevo()));
}
if (notificacion.categoria == "News and Promos") {
Navigator.push(context, MaterialPageRoute(builder: (context) => PrivateAreaNuevoDos()));
}
},
child: Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Card(
elevation: 0,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(width: 10),
notificacion.categoria == "Travel Document"
? const CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage("assets/item2.png"),
backgroundColor: Colors.transparent,
)
: notificacion.categoria == "Itinerary"
? const CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage("assets/item3.png"),
backgroundColor: Colors.transparent,
)
: notificacion.categoria == "Experience"
? const CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage("assets/item4.png"),
backgroundColor: Colors.transparent,
)
: const CircleAvatar(
radius: 20.0,
backgroundImage: AssetImage("assets/logolc.png"),
backgroundColor: Colors.transparent,
),
const SizedBox(width: 15),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 199,
height: 40,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"$textoNot",
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
],
),
),
],
),
const Spacer(),
GestureDetector(
onTap: () {},
child: notificacion.categoria == "Push"
? Container()
: IconButton(
onPressed: () {
if (notificacion.categoria == "Travel Document") {
Navigator.push(context, MaterialPageRoute(builder: (context) => BDTravelDocumentsNuevo()));
}
if (notificacion.categoria == "Itinerary") {
Navigator.push(context, MaterialPageRoute(builder: (context) => BDItineraryNuevo()));
}
if (notificacion.categoria == "Experience") {
Navigator.push(context, MaterialPageRoute(builder: (context) => BDExperiencesNuevo()));
}
if (notificacion.categoria == "News and Promos") {
Navigator.push(context, MaterialPageRoute(builder: (context) => PrivateAreaNuevoDos()));
}
},
icon: const Icon(
Icons.arrow_forward_ios,
),
),
),
],
),
),
),
),
),
),
),
),
);
},
);
}
return AnyNotification();
},
),

Could not find the correct Provider<User> above this MainScreenPage Widget

I am getting the Error: Could not find the correct Provider above this MainScreenPage Widget. I cannot figure out what is wrong with my code since my MultiProvider is the parent of MaterialApp.
Things I tried which did not help:
Stopped debugging and started debugging.
Moved MultiProvider inside runApp, making MyApp its child.
I would very much appreciate it if anybody could help.
What shown on debug console
The relevant error-causing widget was
MainScreenPage lib/main.dart:22 (that is "widget = MainScreenPage();")
<main.dart>
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
User? firebaseUser = FirebaseAuth.instance.currentUser;
Widget widget;
if (firebaseUser != null) {
print(firebaseUser.email);
widget = MainScreenPage();
} else {
widget = LoginPage();
}
return MultiProvider(
providers: [
StreamProvider<User?>(
initialData: null,
create: (context) => FirebaseAuth.instance.authStateChanges(),
)
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'BookTracker',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: GoogleFonts.notoSansTextTheme(
Theme.of(context).textTheme,
),
),
home: widget,
),
);
}
}
<main_screen_page.dart>
class MainScreenPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
CollectionReference userCollectionReference =
FirebaseFirestore.instance.collection('users');
CollectionReference bookCollectionReference =
FirebaseFirestore.instance.collection('books');
List<Book> userBooksReadList = [];
// int booksRead = 0;
var authUser = Provider.of<User>(context);
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white24,
elevation: 0,
toolbarHeight: 77,
centerTitle: false,
title: Row(
children: [
Text(
'A.Reader',
style: Theme.of(context).textTheme.headline6!.copyWith(
color: Colors.redAccent, fontWeight: FontWeight.bold),
),
],
),
actions: [
StreamBuilder<QuerySnapshot>(
stream: userCollectionReference.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
final userListStream = snapshot.data!.docs.map((user) {
return MUser.fromDocument(user);
}).where((user) {
return (user.uid == authUser.uid);
}).toList();
MUser curUser = userListStream[0];
return Column(
children: [
InkWell(
child: SizedBox(
height: 40,
width: 40,
child: CircleAvatar(
radius: 60,
backgroundImage: NetworkImage(curUser.avatarUrl ??
'https://picsum.photos/id/1022/300'),
backgroundColor: Colors.white,
child: Text(''),
),
),
onTap: () {
showDialog(
context: context,
builder: (context) {
return createProfileDialog(
context, curUser, userBooksReadList);
},
);
},
),
Text(
curUser.displayName.toUpperCase(),
overflow: TextOverflow.ellipsis,
style: TextStyle(color: Colors.black),
)
],
);
},
),
TextButton.icon(
onPressed: () {
FirebaseAuth.instance.signOut().then((value) {
return Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginPage(),
));
});
},
icon: Icon(Icons.logout),
label: Text(''),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BookSearchPage(),
));
},
child: Icon(
Icons.add,
),
backgroundColor: Colors.redAccent,
),
body: Column(
children: [
Container(
width: double.infinity,
margin: const EdgeInsets.only(top: 12, left: 12, bottom: 10),
child: RichText(
text: TextSpan(
style: Theme.of(context).textTheme.headline6,
children: [
TextSpan(text: '今、'),
TextSpan(
text: '読んでいるのは',
style: TextStyle(fontWeight: FontWeight.w600)),
TextSpan(text: '…'),
]),
),
),
SizedBox(
height: 10,
),
StreamBuilder<QuerySnapshot>(
stream: bookCollectionReference.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text('問題が発生しました (T.T)');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Expanded(
flex: 1,
child: Center(
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.lime.shade300,
)));
}
if (snapshot.data!.docs.isEmpty) {
return Text('表示する書籍データがありません',
style: Theme.of(context).textTheme.headline4);
}
final userBookFilteredReadListStream =
snapshot.data!.docs.map((book) {
return Book.fromDocument(book);
}).where((book) {
return ((book.userId == authUser.uid)) &&
(book.finishedReading == null) &&
(book.startedReading != null);
}).toList();
userBooksReadList = snapshot.data!.docs.map((book) {
return Book.fromDocument(book);
}).where((book) {
return ((book.userId == authUser.uid)) &&
(book.finishedReading != null) &&
(book.startedReading != null);
}).toList();
return Expanded(
flex: 1,
child: (userBookFilteredReadListStream.length > 0)
? ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: userBookFilteredReadListStream.length,
itemBuilder: (context, index) {
Book book = userBookFilteredReadListStream[index];
return InkWell(
child: ReadingListCard(
buttonText: '読書中',
image: book.photoUrl!,
title: book.title,
author: book.author!,
rating: (book.rating) != null ? book.rating : 0,
),
onTap: () {
showDialog(
context: context,
builder: (context) {
return BookDetailDialog(
book: book,
);
},
);
},
);
},
)
: Text('読書中の本はありません (・o・)',
style: Theme.of(context).textTheme.headline6));
},
),
Container(
width: double.infinity,
margin: EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: TextSpan(children: [
TextSpan(
text: '読みたい本リスト',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w600,
color: kBlackColor),
),
]),
),
],
),
),
SizedBox(
height: 8,
),
StreamBuilder<QuerySnapshot>(
stream: bookCollectionReference.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text('問題が発生しました (T.T)');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Expanded(
flex: 1,
child: Center(
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.lime.shade300,
)));
}
if (snapshot.data!.docs.isEmpty) {
return Center(
child: Text('表示する書籍データがありません',
style: Theme.of(context).textTheme.headline4),
);
}
final readingListListBook = snapshot.data!.docs.map((book) {
return Book.fromDocument(book);
// ログイン中ユーザのuidでbookをフィルタリングする
}).where((book) {
return ((book.userId == authUser.uid)) &&
(book.startedReading == null) &&
(book.finishedReading == null);
}).toList();
return Expanded(
flex: 1,
child: (readingListListBook.length > 0)
? ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: readingListListBook.length,
itemBuilder: (context, index) {
Book book = readingListListBook[index];
return InkWell(
child: ReadingListCard(
buttonText: '未読',
rating: (book.rating) != null ? book.rating : 0,
image: book.photoUrl!,
title: book.title,
author: book.author!,
isBookRead: false,
),
onTap: () {
showDialog(
context: context,
builder: (context) {
return BookDetailDialog(
book: book,
);
},
);
},
);
},
)
: Text('表示する書籍データがありません ^_^;',
style: Theme.of(context).textTheme.headline6));
},
),
],
),
);
}
}
"var authUser = Provider.of<User>(context);" could you add a question mark to this syntax? It should look like this: "var authUser = Provider.of<User?>(context);"

Flutter - whitespaces displaying for image in portrait and landscape

I keep seeing lot of white space if I do landscape or portrait within my image. I do need the slidable so didn't want to tweak the code too much, but I do want it to look representable
is there something wrong with my code?
I did add a picture this is happening in both landscape and portrait mode
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: new Text(
"1 Alif-laam-meem آلم, Pg2",
style: new TextStyle(color: styling.appBarTextcolor),
),
leading: new IconButton(
icon: new Icon(styling.appBarBackArrowIcon),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NavDrawer(),
));
})),
body: LayoutBuilder(builder:
(BuildContext context, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: Stack(children: <Widget>[
new Slidable(
delegate: new SlidableDrawerDelegate(),
actionExtentRatio: styling.sizeofenglishandforward,
child: SafeArea(
top: true,
bottom: true,
right: true,
left: true,
child: new Container(
child: new Image.asset(
"test/assets/Para 1 - Alif-laam-meem no color/quranpg2-1.png",
// fit: BoxFit.fitidth,
fit: BoxFit.cover,
),
),
),
actions: <Widget>[
new IconSlideAction(
caption: styling.englishIconText,
color: styling.englishIconColorstripe,
icon: styling.englishIcon,
foregroundColor: styling.englishIconColor,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Changepg2topg2Color()),
);
}),
new IconSlideAction(
caption: styling.forwardIconText,
color: styling.forwardIconColorstripe,
icon: styling.forwardIcon,
foregroundColor: styling.forwardIconColor,
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => Changepg2topg3()),
// );
// }
),
// ),
],
secondaryActions: <Widget>[
new IconSlideAction(
caption: styling.backIconText,
color: styling.backIconColorstripe,
icon: styling.backIcon,
foregroundColor: styling.backIconColor,
// onTap: () => _showSnackBar('More'),
),
new IconSlideAction(
caption: styling.arabicIconText,
color: styling.arabicIconColorstripe,
icon: styling.arabicIcon,
foregroundColor: styling.arabicIconColor,
// onTap: () =>
),
],
),
]));
}));
}
}
SafeArea is preventing your image to go at some restricted areas of screen like, underneath the notch area. Or for some devices there are NavigationKeys in the bottom of screen. Try removing these
Cheers :)
child: SafeArea(
top: true,
bottom: true,
right: true,
left: true,

How to deal with setState properly

void showSimpleCustomDialog(BuildContext context, String listName) async{
if(randList.isEmpty){
randList = await theDb.queryWhere("$listName");
}else{
randList.clear();
randList = await theDb.queryWhere("$listName");
}
setState((){
});
String randValue = "Click generate new to get a random value";
Dialog simpleDialog = Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
child: Text(
"$randValue"
),
),
Padding(
child: Row(
children: <Widget>[
RaisedButton(
color: Colors.blue,
onPressed: ()
String lol = randList[0 + rng.nextInt(randList.length - 0)].getItem();
print(randValue);
setState(() {
randValue = lol;
});
},
child: Text(
'generate new',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
)
],
),
),
],
),
),
);
showDialog(
context: context, builder: (BuildContext context) => simpleDialog);}
When I am clicking on "generate new" button I want to update my randomValue and to display that randomValue as Text Widget. To do that dynamically Im using setState, but it is not working, and i dont understand why. Please help me.
You should use StatefulBuilder with dialogue.
showDialog(
context: context,
builder: (context) {
String contentText = "Content of Dialog";
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
title: Text("Title of Dialog"),
content: Text(contentText),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.pop(context),
child: Text("Cancel"),
),
FlatButton(
onPressed: () {
setState(() {
contentText = "Changed Content of Dialog";
});
},
child: Text("Change"),
),
],
);
},
);
},

How did i setup popup AlertDialog?

How did i setup popup AlertDialog when int is equal or greater than 100?
showDialog(
context: _context,
builder: (BuildContext context) => AlertDialog(
title: Text("$_winner Won"),
)
);
void scoreTeamA() {
setState(() {
outputTeamA += _choiceA;
});
}
// I would like to show outputTeamA on the AlertDialog
Thank you
Mohammad
One way is to create a Widget for the AlertDialog and pass the String/Widget you want to show on that dialog.
class LoadingDialog{
static Future<void> showLoadingDialog(BuildContext context,String text) async {
return showDialog(
context: context,
builder: (BuildContext context){
return SimpleDialog(
children: <Widget>[
Center(
child: Container(
child: Column(
children: <Widget>[
SizedBox(
height:10,
),
Text(text),
]
),
),
),
],
),
}
);
}
}
then you can call on an Event like:
void scoreTeamA(){
outputTeamA += _choiceA;
LoadingDialog.showLoadingDialog(context, outputTeamA);
}
Note: this code might have some errors. i haven't tested this.
This is how I display an AlertDialog
showAlertDialog() {
return showDialog(
context: context,
builder: (context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
side: BorderSide(color: Colors.redAccent, width: 2.0),
),
elevation: 6,
titlePadding: EdgeInsets.all(8.0),
titleTextStyle: TextStyle(
fontSize: 18, color: Colors.red, fontWeight: FontWeight.bold),
title: Text(
'This is the alert title',
textAlign: TextAlign.center,
),
contentPadding: EdgeInsets.all(8.0),
contentTextStyle: TextStyle(fontSize: 14, color: Colors.black),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Content...')
//content goes here
],
),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.of(context).pop(), child: Text('Okay'))
],
),
);
}
And then you would do your if check to check
if( outputTeamA >= 100){
showAlertDialog();
}
Of course you could use outputTeamA in AlertDialog