How can I narrow the width of the popup menu in the navbar?
How can I zoom the icon and text?
I can't open the width tag, I think a different customization is required.
actions: <Widget>[
PopupMenuButton<_MenuValues>(
color: const Color(0xFF212121),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0))
),
itemBuilder: (BuildContext context) => [
PopupMenuItem(
child: ListTile(
leading: Icon(Icons.settings, color: Colors.white),
title: Text("Settings", style: TextStyle(color: Colors.white)),
),
value: _MenuValues.settings
),
],
onSelected: (value) {
switch(value) {
case _MenuValues.settings:
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => settings(),
));
break;
}
},
),
],
use sizedBox
PopupMenuItem(
value: 1,
// row has two child icon and text.
child: SizedBox(
width: 500,
child: Row(
children: [
Icon(Icons.settings , size: 10,),
Text("Settings", style: TextStyle(fontSize: 10),)
],
),
)
),
],
Related
I am a beginner with flutter, I had just started a few days ago. I want to go from one page to another page . But when I use the navigator it shows an error.
I've tried to solve it using some answers to similar problems on stack overflow, but I can't solve it. Also, I am not able to understand those properly.
These are some of them:
Undefined name 'context'
_buildDrawer() {
return ClipPath(
clipper: OvalRightBorderClipper(),
child: Drawer(
child: Container(
padding: const EdgeInsets.only(left: 16.0, right: 40),
decoration: BoxDecoration(
color: primary, boxShadow: [BoxShadow(color: Colors.black45)]),
width: 300,
child: SafeArea(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
alignment: Alignment.centerRight,
child: IconButton(
icon: Icon(
Icons.power_settings_new,
color: active,
),
onPressed: () {},
),
),
Container(
height: 90,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient:
LinearGradient(colors: [Colors.pink, Colors.red])),
child: CircleAvatar(
radius: 40,
backgroundImage: NetworkImage(profile),
),
),
SizedBox(height: 5.0),
Text(
"Mohd Amin bin Yaakob",
style: TextStyle(color: Colors.white, fontSize: 18.0),
),
Text(
"Pegawai",
style: TextStyle(color: active, fontSize: 16.0),
),
SizedBox(height: 30.0),
_buildRow(Icons.home, "Home", () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) {
return HomePageWidgetPage();
},
),
);
}),
_buildDivider(),
_buildRow(Icons.home, "Home", () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) {
return HomePageWidgetPage();
},
),
);
}),
_buildDivider(),
_buildRow(Icons.home, "Home", () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) {
return HomePageWidgetPage();
},
),
);
}),
_buildDivider(),
_buildRow(Icons.home, "Home", () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) {
return HomePageWidgetPage();
},
),
);
}),
_buildDivider(),
_buildRow(Icons.home, "Home", () {
Navigator.push(context,
MaterialPageRoute(
builder: (context) {
return HomePageWidgetPage();
},
),
);
}),
_buildDivider(),
],
),
),
),
),
),
);
}
Divider _buildDivider() {
return Divider(
color: active,
);
}
Widget _buildRow(IconData icon, String title, VoidCallback onTap) {
final TextStyle tStyle = TextStyle(color: active, fontSize: 16.0);
return InkWell(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Icon(
icon,
color: active,
),
SizedBox(width: 10.0),
Text(
title,
style: tStyle,
),
],
),
),
onTap: onTap,
);
}
}
Undefined name 'context' in flutter navigation
You can pass the context like
_buildDrawer(BuildContext context){
And the place you call this method
_buildDrawer(context)
I want to floating action button is front of the alert dialog, I tried add elevation to floatingactionbutton and alertdialog but still not working. is it possible to make floatingactionbutton overlapping all layout including alertdialog?
this my alertdialog using lib rflutter_alert
var alertStyle = AlertStyle(
// animationType: AnimationType.fromTop,
alertElevation: 1,
isCloseButton: false,
isOverlayTapDismiss: false,
descStyle: TextStyle(fontSize: textBody3),
descTextAlign: TextAlign.center,
titleStyle: TextStyle(
color: Colors.red,
fontSize: textHeader1,
fontWeight: FontWeight.bold),
alertAlignment: Alignment.center,
);
Alert(
context: context,
style: alertStyle,
content: Column(
children: <Widget>[
const SizedBox(
height: 30,
),
Text(msg),
const SizedBox(
height: 30,
),
Text(jam)
],
),
buttons: [
DialogButton(
child: Text(
"OK",
style: TextStyle(color: Colors.white, fontSize: textButton1),
),
onPressed: () => Navigator.pop(context),
color: Palette.color_primary,
radius: BorderRadius.circular(0.0),
),
],
image: flag == "OK"
? Image.asset(
"assets/images/success.png",
height: 50,
width: 50,
)
: Image.asset(
"assets/images/error.png",
height: 50,
width: 50,
),
).show();
and this the floatingactionbutton using lib DraggableFab
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: DraggableFab(
child: FloatingActionButton.extended(
elevation: 10,
onPressed: () {
getLocation();
},
label:ValueListenableBuilder(
valueListenable: notifierLocFab,
builder: (BuildContext context, bool value,Widget? child) {
return Column(
children: [
Text(latitudeFab.toStringAsFixed(7)),
Text(longitudeFab.toStringAsFixed(7)),
],
);
}),
),
),
);
}
I'm utilize o Slidable on app Flutter and put as ListTile child.
So far ok.
I'm problem is i would like when I slide it to the left the text keeps appearing on the screen, as shown in the image below.(Red == Title)
At the moment the text is hidden when I swipe, as per the image.(Red == Title)
I saw that when I swipe this attribute changes state Slidable.of(context)?.animation.isCompleted
And I also verified that in my Row title of ListTile, if I line up the title as End, the title will appear msm by swiping.
So I thought, as this Slidable.of(context)?.animation.isCompleted attribute changes state I align my Row to Start or End.
But I couldn't find a way to monitor this attribute, so that when it changes I can rebuild my Row. I tried to put it as Stream but I wasn't successful. Because it looks like it doesn't generate an event, it just changes the value.
I don't know how I could do it, if anyone has any tips...
Code:
#override
Widget build(BuildContext) {
return Slidable(
key: const ValueKey(1),
endActionPane: ActionPane(
motion: const DrawerMotion(),
children: [
SlidableAction(
onPressed: (ctx) => {
Get.to(() => const CredentialOperationScreen(),
arguments:
RouteDetailCredential(itemCredential: itemCredential))
},
backgroundColor: ConstsColors.orangeAccent,
foregroundColor: Colors.white,
icon: Icons.info_outline,
),
SlidableAction(
onPressed: (ctx) => {
Get.to(() => const CredentialOperationScreen(),
arguments:
RouteDeleteCredential(itemCredential: itemCredential))
},
backgroundColor: const Color.fromRGBO(219, 32, 32, 1),
foregroundColor: Colors.white,
icon: Icons.delete_outline,
),
],
),
child: Builder(
builder: (ctx) {
return Container(
child: _listTile(ctx),
decoration: const BoxDecoration(
border: Border(
bottom:
BorderSide(color: ConstsColors.greyColorOpacity))));
},
));
}
Widget _listTile(context) {
return ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
itemCredential.icon,
color: Colors.black,
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
itemCredential.name,
style: const TextStyle(
fontFamily: 'Roboto',
fontSize: 16,
),
),
),
],
),
onTap: () => {
Slidable.of(context)?.animation.isCompleted == true
? Slidable.of(context)?.close()
: Slidable.of(context)?.openEndActionPane()
},
trailing: const Icon(Icons.check_circle_outline, color: Colors.green),
);
}
I'm dynamically removing children from a SliverGrid.count but when all children are removed the SliverGrid throws the Exception SliverGeometry is not valid: The "scrollExtent" is negative.
I think this error happens because when the list of children is empty the Grid has no children to render anymore and can't render itself. When I also just place a Container (which isn't removable) at the top of my dynamic list of children the error doesn't happen but the rest of my children get pushed down becuase of the AxisSpacing.
Is there another way to fix this issue than just placing a static `Container at the top or bottom of the children?
This is the code from my SliverGrid and the layout is also shown in an image below:
SliverGrid.count(
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
crossAxisCount: segmentedControlGroupValue,
children: <Widget>[
for (var i = 0;
i < sessionState.patientQuestionnaires.length;
i++)
Material(
color: Colors.white,
borderRadius: BorderRadius.circular(6),
elevation: 6,
shadowColor: Colors.black38,
child: InkWell(
onTap: () => showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => PQBottomSheet(
i: i,
),
),
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Row(children: [
Expanded(
child: Wrap(
runAlignment: WrapAlignment.center,
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Icon(
Icons.assignment,
color: Theme.of(context).primaryColor,
size: segmentedControlGroupValue == 1
? 30
: segmentedControlGroupValue == 2
? 28
: 24,
),
Text(
sessionState.patientQuestionnaires[i]
.credentialSubject.documentName,
style:
Theme.of(context).textTheme.bodyText1,
overflow: TextOverflow.ellipsis,
),
Text(
DateFormat.yMMMd().format(DateTime.parse(
sessionState
.patientQuestionnaires[i]
.issuanceDate)
.toLocal()),
style: Theme.of(context)
.textTheme
.bodyText2!
.copyWith(
color: Theme.of(context)
.colorScheme
.onBackground
.withOpacity(0.5),
),
overflow: TextOverflow.ellipsis,
),
],
),
),
IconButton(
padding: const EdgeInsets.all(0.0),
visualDensity: VisualDensity.compact,
onPressed: () => Platform.isAndroid
? showCupertinoModalPopup(
useRootNavigator: false,
context: context,
builder: (context) =>
CupertinoActionSheet(
actions: [
CupertinoActionSheetAction(
onPressed: () {},
child: Text(L.of(context).share),
),
CupertinoActionSheetAction(
onPressed: () {
Navigator.of(context).pop();
setState(() {
context
.read<SessionCubit>()
.deletePQ(
i, sessionState);
});
},
child: Text(
L.of(context).delete,
style: TextStyle(
color: Theme.of(context)
.errorColor),
),
),
],
cancelButton:
CupertinoActionSheetAction(
onPressed: () =>
Navigator.of(context).pop(),
child: Text(
L.of(context).cancel,
),
),
),
)
: bottomSheet(
context: context,
buttons: [
SizedBox(
width: double.infinity,
child: TextButton(
onPressed: () {},
child: Text(L.of(context).share,
style: Theme.of(context)
.textTheme
.bodyText1),
),
),
SizedBox(
width: double.infinity,
child: TextButton(
onPressed: () {
Navigator.of(context).pop();
setState(() {
context
.read<SessionCubit>()
.deletePQ(
i, sessionState);
});
},
child: Text(
L.of(context).delete,
style: Theme.of(context)
.textTheme
.bodyText1!
.copyWith(
color: Theme.of(context)
.errorColor,
),
),
),
),
],
),
icon: const Icon(Icons.more_vert))
]),
),
),
),
],
),
Removing the complete SilverGrid widget when there are no items present might work. Because there has to be at least one widget inside the Grid.
if (sessionState.patientQuestionnaires.length > 0)
SilverGrid.count(...),
Adding the above code will make the SilverGrid disappear and again appear when you add some content to the patientQuestionnaires.
Note: You need to setState() or an alternative to refresh the state when the item is removed/added. (Hopefully, you are already using one)
i'm a bit new to flutter and i'm trying to teach myself to build a groceries list, which will be linked to an API backend. I want the text on a listtile to be editable ontap, so if the user makes a typo they can quickly edit the listtile without going through an additional dialogue.
Screenshot of list tiles
Code:
Widget _shoppingListItem() {
return ListView.builder(
itemCount:
_shoppingList.shoppingListCategories.first.shoppingListItems.length,
itemBuilder: (context, index) {
return Dismissible(
background: Container(
child: Text("Delete",
style: TextStyle(
fontWeight: FontWeight.normal, color: Colors.white)),
color: Colors.red,
),
confirmDismiss: (direction) {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Sure??'),
content: Text('Delete'),
actions: <Widget>[
FlatButton(
onPressed: () {
// Navigator.pop(context, false);
Navigator.of(
context,
// rootNavigator: true,
).pop(false);
},
child: Text('No'),
),
FlatButton(
onPressed: () {
// Navigator.pop(context, true);
Navigator.of(
context,
// rootNavigator: true,
).pop(true);
},
child: Text('Yes'),
),
],
);
},
);
},
key: UniqueKey(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 1,
blurRadius: 6,
offset: Offset(0, 3), // changes position of shadow
),
],
),
child: ListTile(
title: Text(
_shoppingList.shoppingListCategories.first
.shoppingListItems[index].itemName,
style:
TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
color: ColorPalette.dark2,
icon: icons.shoppingMinus.image(size: 24),
onPressed: () {
setState(() {
_shoppingList.shoppingListCategories.first
.shoppingListItems[index].itemCount--;
});
},
),
Text(
"${_shoppingList.shoppingListCategories.first.shoppingListItems[index].itemCount}",
style: TextStyle(
color: ColorPalette.dark2,
),
),
IconButton(
color: ColorPalette.dark2,
icon: icons.shoppingPlus.image(size: 24),
onPressed: () {
setState(() {
_shoppingList.shoppingListCategories.first
.shoppingListItems[index].itemCount++;
});
},
),
],
),
),
),
),
);
},
);
}
}