Not able to align floating action menu in flutter - flutter

I have this menu on the floating button , but I could not align it correctly,
I want it to show directly above the floating button, this is how it looks in red box:
I want the pop up menu to be like this in red box , I tried to change offset number but did not work it just moves left and right
please help me find a solution I'm really struggling, I provided the code below please check it out
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: myPopMenu(context),
backgroundColor: Colors.white,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomNav(
onChange: (a) {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (c) => AppPage(initialPage: a,)),
(route) => false);
},
),
);
}
Widget myPopMenu(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
cardColor: Colors.white60,
),
child: PopupMenuButton(
offset: const Offset(-90, 100),
icon: Image.asset('assets/logo.png', fit: BoxFit.cover, height: 40),
onCanceled: () {
setState(() {
isClicked = false;
});
},
onSelected: (value) {
setState(() {
isClicked = false;
});
print('pop up clicked');
if (value == 0) {
alertRate();
} else if (value == 1){
alertServices();
}else if (value == 2) {
alertAdditonalInfo();
}else if (value == 3){
alertReport();
}
},
itemBuilder: (context) {
setState(() {
isClicked = true;
});
return [
PopupMenuItem(
child: Center(
child: Text(
'Rate & Review',
style: TextStyle(color: Colors.black),
),
),
value: 0,
),
PopupMenuItem(
height: 4,
child: Container(
height: 2,
color: Colors.black,
),
),
PopupMenuItem(
child: Center(
child: Text(
'Edit Available Services',
style: TextStyle(color: Colors.black),
),
),
value: 1,
),
PopupMenuItem(
height: 4,
child: Container(
height: 2,
color: Colors.black,
),
),
PopupMenuItem(
child: Center(
child: Text(
'Edit Social Accounts',
style: TextStyle(color: Colors.black),
),
),
value: 2,
),
PopupMenuItem(
height: 4,
child: Container(
height: 2,
color: Colors.black,
),
),
PopupMenuItem(
child: Center(
child: Text(
'Report an Issue',
style: TextStyle(color: Colors.black),
),
),
value: 3,
),
];
}),
);
}

You can use stack and positioned widget to place it at specific height above bottom nav bar like this
class Sample extends StatelessWidget {
const Sample({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
alignment: Alignment.center,
children: [
Positioned(
bottom: 30,
child: Container(
color: Colors.grey,
width: 50,
height: 30,
child: Text('Hello'),
),
)
],
,
);
}
}

Related

Flutter || Checkbox on hover doesn't give on tap cursor permission

I am working on dropdownmenu items where in the drop-down menu item there are several checkboxes but any of the checkboxes on hover don't give on tap cursor permission.
This is a very strange thing I found out as I have already used the checkbox before but this type of error I didn't receive.
I think maybe the problem is in dropdownmenu.
I have also included the video for better understanding of my problem.
my code :-
Container(
width: 160,
//margin: const EdgeInsets.only(top: 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5), color: Colors.white),
child: ListTileTheme(
contentPadding: EdgeInsets.all(0),
dense: true,
horizontalTitleGap: 0.0,
minLeadingWidth: 0,
child: ExpansionTile(
iconColor: primaryBackgroundLightGrey,
title: Text(
listOFSelectedItem.isEmpty
? "Project type"
: listOFSelectedItem[0],
style: t5O40),
children: <Widget>[
Container(
height: 10,
color: primaryBackgroundLightGrey,
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: widget.listOFStrings.length,
itemBuilder: (BuildContext context, int index) {
return Column(
children: [
Container(
height: 10,
),
Container(
margin: const EdgeInsets.only(bottom: 8.0),
child: _ViewItem(
item: widget.listOFStrings[index],
selected: (val) {
selectedText = val;
if (listOFSelectedItem.contains(val)) {
listOFSelectedItem.remove(val);
} else {
listOFSelectedItem.add(val);
}
widget.selectedList(listOFSelectedItem);
setState(() {});
},
itemSelected: listOFSelectedItem
.contains(widget.listOFStrings[index])),
),
],
);
},
),
],
),
),
),
class _ViewItem extends StatelessWidget {
String item;
bool itemSelected;
final Function(String) selected;
_ViewItem(
{required this.item, required this.itemSelected, required this.selected});
#override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Padding(
padding: EdgeInsets.only(
left: size.width * .015,
),
child: Row(
children: [
SizedBox(
height: 2,
width: 2,
child: Checkbox(
value: itemSelected,
onChanged: (val) {
selected(item);
},
hoverColor: Colors.transparent,
checkColor: Colors.white,
activeColor: Colors.grey),
),
SizedBox(
width: size.width * .010,
),
Text(item, style: t3O60),
],
),
);
}
}
You can adapt the example to your own code
dropdownBuilder: _customDropDownExample,
popupItemBuilder: _customPopupItemBuilderExample,
Widget _customDropDownExample(
BuildContext context, UserModel? item, String itemDesignation) {
if (item == null) {
return Container();
}
return Container(
child: (item.avatar == null)
? ListTile(
contentPadding: EdgeInsets.all(0),
leading: CircleAvatar(),
title: Text("No item selected"),
)
: ListTile(
contentPadding: EdgeInsets.all(0),
leading: CircleAvatar(
// this does not work - throws 404 error
// backgroundImage: NetworkImage(item.avatar ?? ''),
),
title: Text(item.name),
subtitle: Text(
item.createdAt.toString(),
),
),
);
After that
Widget _customPopupItemBuilderExample(
BuildContext context, UserModel item, bool isSelected) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 8),
decoration: !isSelected
? null
: BoxDecoration(
border: Border.all(color: Theme.of(context).primaryColor),
borderRadius: BorderRadius.circular(5),
color: Colors.white,
),
child: ListTile(
selected: isSelected,
title: Text(item.name),
subtitle: Text(item.createdAt.toString()),
leading: CircleAvatar(
// this does not work - throws 404 error
// backgroundImage: NetworkImage(item.avatar ?? ''),
),
),
);
I am using this package https://pub.dev/packages/dropdown_button2
Multiselect Dropdown with Checkboxes
final List<String> items = [
'Item1',
'Item2',
'Item3',
'Item4',
];
List<String> selectedItems = [];
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: DropdownButtonHideUnderline(
child: DropdownButton2(
isExpanded: true,
hint: Align(
alignment: AlignmentDirectional.center,
child: Text(
'Select Items',
style: TextStyle(
fontSize: 14,
color: Theme.of(context).hintColor,
),
),
),
items: items.map((item) {
return DropdownMenuItem<String>(
value: item,
//disable default onTap to avoid closing menu when selecting an item
enabled: false,
child: StatefulBuilder(
builder: (context, menuSetState) {
final _isSelected = selectedItems.contains(item);
return InkWell(
onTap: () {
_isSelected
? selectedItems.remove(item)
: selectedItems.add(item);
//This rebuilds the StatefulWidget to update the button's text
setState(() {});
//This rebuilds the dropdownMenu Widget to update the check mark
menuSetState(() {});
},
child: Container(
height: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
_isSelected
? const Icon(Icons.check_box_outlined)
: const Icon(Icons.check_box_outline_blank),
const SizedBox(width: 16),
Text(
item,
style: const TextStyle(
fontSize: 14,
),
),
],
),
),
);
},
),
);
}).toList(),
//Use last selected item as the current value so if we've limited menu height, it scroll to last item.
value: selectedItems.isEmpty ? null : selectedItems.last,
onChanged: (value) {},
buttonHeight: 40,
buttonWidth: 140,
itemHeight: 40,
itemPadding: EdgeInsets.zero,
selectedItemBuilder: (context) {
return items.map(
(item) {
return Container(
alignment: AlignmentDirectional.center,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Text(
selectedItems.join(', '),
style: const TextStyle(
fontSize: 14,
overflow: TextOverflow.ellipsis,
),
maxLines: 1,
),
);
},
).toList();
},
),
),
),
);
}

flutter how to floatingactionbutton overlapping alertdialog?

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)),
],
);
}),
),
),
);
}

Flutter toast dialog

How can I can make such toast dialog in flutter? (create service, create venue)
Interactive example:
https://files.fm/f/dw6qvmznc
You can use PopupMenuButton
PopupMenuButton<String>(
icon: const Icon(Icons.add_circle_outline_outlined),
color: Colors.grey, // background color
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: "create service",
onTap: () {},
child: const Center(
child: Text(
'create service',
),
),
),
PopupMenuItem<String>(
value: "create venue",
child: const Center(
child: Text(
'create venue',
),
),
onTap: () {},
),
],
)
Here's a neat package that takes care of that with different styles as well.
StarMenu(
onStateChanged: (state) {
print('State changed: $state');
},
params: StarMenuParameters(
shape: MenuShape.linear,
linearShapeParams: LinearShapeParams(
angle: 270,
space: 30,
alignment: LinearAlignment.center),
onItemTapped: (index, controller) {
// don't close if the item tapped is not the ListView
if (index != 1) controller.closeMenu();
}),
// lazyItemsLoad let you build menu entries at runtime
lazyItems: () async {
return [
Container(
color: Color.fromARGB(255, Random().nextInt(255),
Random().nextInt(255), Random().nextInt(255)),
width: 60,
height: 40,
),
Container(
width: 150, // CHANGE WIDTH
height: 200, // CHANGE HEIGHT
child: Card(
elevation: 6,
margin: EdgeInsets.all(6),
child: Column(
children: [
// ADD YOUR ACTIONS HERE
]
),
),
),
),
];
},
child: FloatingActionButton( // THIS WILL BE YOUR BUTTON YOU WANT TO SHOW THE MENU FROM
onPressed: () {
print('FloatingActionButton Menu1 tapped');
},
child: Icon(Icons.looks_one),
),
),
You can simple Dialog of CupertinoDailog...
onPress:(){
showCupertinoDialog(context: context,
builder: (context) {
return CupertinoAlertDialog(
content: Column(
children: [
Text("Option 1"),
Text("Option 1"),
Text("Option 1"),
],
),
);})
}

Reset a List when finished

I have a list of strings that are rendered in swipeable cards. What I want to achieve is that when the users finishes the cards, There is a button to "retry again" and the list of Strings is reset and retrieved again.
This is what i achieved so far:
class _ExampleHomePageState extends State<ExampleHomePage> with TickerProviderStateMixin {
List<String> truths = [
"Hello",
"Hello2",
"Hello3",
"Hello4",
"Hello5",
"Hello6",
"Hello7",
"Hello7",
"Hello7",
"Hello7",
];
#override
Widget build(BuildContext context) {
CardController controller;
return Scaffold(
backgroundColor: Colors.black45,
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.white,
title: Text(
'The truth game',
style: TextStyle(color: Colors.redAccent),
),
),
body: Container(
height: MediaQuery.of(context).size.height * 0.7,
child: TinderSwapCard(
orientation: AmassOrientation.BOTTOM,
totalNum: 6,
stackNum: 4,
swipeEdge: 4.0,
maxWidth: MediaQuery.of(context).size.width * 0.9,
maxHeight: MediaQuery.of(context).size.width * 0.9,
minWidth: MediaQuery.of(context).size.width * 0.8,
minHeight: MediaQuery.of(context).size.width * 0.8,
cardBuilder: (context, index) => Card(
child: Center(
child: Text(
'${truths[index]}',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
)),
),
cardController: controller = CardController(),
swipeUpdateCallback: (DragUpdateDetails details, Alignment align) {
if (align.x < 0) {
} else if (align.x > 0) {
return {
};
}
},
swipeCompleteCallback: (CardSwipeOrientation orientaion, int index) {
GestureDetector(
child: Text('try me again'),
onTap: (){
},
);
},
)),
bottomNavigationBar: CurvedNavigationBar(
color: Colors.white,
backgroundColor: Colors.transparent,
buttonBackgroundColor: Colors.white,
height: 70.0,
items: <Widget>[
Icon(
Icons.home,
size: 30.0,
color: Colors.redAccent,
),
Icon(
Icons.chat_bubble,
size: 30.0,
color: Colors.redAccent,
),
Icon(
FontAwesomeIcons.heart,
size: 30.0,
color: Colors.redAccent,
),
],
),
);
}
}
I tried setting the SetState(){} method, but its not reseting the list.
you can reset your whole widget by :
void _reset() {
Navigator.pushReplacement(
context,
PageRouteBuilder(
transitionDuration: Duration.zero,
pageBuilder: (_, __, ___) => MyWidget(),
),
);
}
and call it when you press your resetbutton
swipeCompleteCallback: (CardSwipeOrientation orientaion, int index) {
GestureDetector(
child: Text('try me again'),
onTap: (){
// add this code inside try me again..,
truths.clear();
setState((){});
},
);
},

Resetting Radio List in Flutter

I am still a novice with flutter and I am working on a quiz app right now
In the radio button list whenever the app goes to next question the radio buttons are not getting reset and I will be grateful if someone can guide me on how I can reset radio button on calling next question function
Pseudocode
class _QuizPageState extends State<QuizPage> {
List<dynamic> myQuestion;
_QuizPageState(this.myQuestion);
int i = 0;
int count = 0;
int selectedRadioTile;
int marks = 0;
var selected;
Widget choiceButton(String k, int value) {
return Padding(
padding: EdgeInsets.symmetric(
vertical: 10,
),
child: RadioListTile(
value: value,
groupValue: selectedRadioTile,
title: Container(
child: Text(myQuestion[i][k] ?? "None"),
),
onChanged: (val) {
setSelectedRadioTile(val);
selected = val;
},
activeColor: Colors.green,
selected: true,
),
);
}
void initState() {
selectedRadioTile = 0;
super.initState();
}
setSelectedRadioTile(int val) {
setState(() {
selectedRadioTile = val;
});
}
void checkAnswer() {
var e = int.parse(myQuestion[i]["Answer"]);
if (e == selected) {
marks = marks + 1;
} else {
print("wrong");
}
nextquestion();
}
void nextquestion() {
setState(() {
if (count < 9) {
i = randomBetween(0, myQuestion.length);
} else {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => resultpage(marks: marks),
));
}
});
}
#override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(
"Alert",
),
content: Text("You Can't Go Back At This Stage."),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Ok',
),
)
],
));
},
child: Scaffold(
appBar: AppBar(
elevation: 30.0,
title: Center(
child: Text(
'Quiz',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontFamily: "Quando",
fontWeight: FontWeight.bold,
),
),
),
backgroundColor: Colors.amber[800],
),
body: LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: constraint.maxHeight),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Center(
child: Container(
padding: EdgeInsets.only(top: 20, left: 10),
child: Text(
myQuestion[i]["Question"] ?? "None",
style: TextStyle(
fontSize: 15.0,
fontFamily: "Quando",
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(
height: 20,
),
Expanded(
child: AspectRatio(
aspectRatio: 16 / 11,
child: ClipRect(
child: SizedBox(
height: 50,
child: PhotoView(
imageProvider: AssetImage(
myQuestion[i]["Image"] ?? "None"),
minScale:
PhotoViewComputedScale.contained *
0.5,
maxScale:
PhotoViewComputedScale.covered * 2,
initialScale: 0.6,
backgroundDecoration: BoxDecoration(
color: Theme.of(context).canvasColor,
),
),
),
),
),
),
Text(
"To adjust the image double Tap",
style: TextStyle(
fontFamily: "Quando",
color: Colors.black26,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
SizedBox(
height: 10,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
choiceButton("option1", 1),
choiceButton("option2", 2),
choiceButton("option3", 3),
choiceButton("option4", 4),
],
),
),
Expanded(
flex: 0,
child: RaisedButton(
splashColor: Colors.blueAccent,
color: Colors.blueAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
),
onPressed: () {
checkAnswer();
count = count + 1;
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(
"Explaination",
),
content: Text(
myQuestion[i]["Explanation"] ?? "None",
style: TextStyle(
fontSize: 15.0,
fontFamily: "Quando",
),
),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Ok',
),
)
],
));
},
child: Text(
'Submit',
),
),
),
SizedBox(
height: 40,
)
],
),
),
),
);
},
),
),
);
}
}
You could just set selectedRadioTile to 0 in nextQuestion:
void nextquestion() {
setState(() {
selectedRadioTile = 0;
if (count < 9) {
i = randomBetween(0, myQuestion.length);
} else {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => resultpage(marks: marks),
));
}
});
}