Is there a widget that is kind of like the Modal BottomSheet() where you call using the showModalBottomSheet function, but instead it is not sticking at the bottom but floating in the middle of the screen? like an alert dialog but you can add textField into it.
Do you mean SimpleDialog?
SimpleDialog(
title: Text('Choose food'),
children:[
SimpleDialogOption(
onPressed: () {
Navigator.pop(context, "Pizza"); },
child: const Text('Pizza'),
),
SimpleDialogOption(
onPressed: () {
Navigator.pop(context, "Burger");
},
child: const Text('Burger'),
),
],
elevation: 10,
//backgroundColor: Colors.green,
)
Related
I want to confirm exiting the app when the back button on the appbar is pressed.
appBar: AppBar(
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Save and Exit?'),
content: Text('are you sure you want to save and exit?'),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context, false),
child: Text('No'),
),
FlatButton(
onPressed: () => Navigator.pop(context, true),
child: Text('Yes'),
),
],
);
},
);
// Navigator.pop(context);
},
),
I tried this but didn't work.
I have found some answers on how to do it when the system back button is pressed using WillPopScope but none of them work in my case.
Help me out
You can check it with Navigator.canPop(context) i guess. It will return true or false.
in onPressed you can check it, if it's true you can do Navigator.pop(context) otherwise call showDialog.
there is link of doc
https://api.flutter.dev/flutter/widgets/Navigator/canPop.html
I'm working with flutter. I want to make a CupertinoAlertDialog(iOS style is required). The problem is UI designer require the width and height respectfully are 270 and 140. I have searched in the flutter doc but could not find related property. Is that possible? Thanks for any advice. The basic code I completed is placed below.
showCupertinoDialog(
context: context,
builder: (BuildContext context){
return Theme(
data: ThemeData.dark(),
child: CupertinoAlertDialog(
title: Text('Title'),
content: Text('Some message here'),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Cancle'),
),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('OK'),
),
],
),
);
}
);
I'm just passing an Android application to Flutter, the current problem is as follows:
In Android I have a Fragment with a search button when the search button is clicked, a new fragment is shown with a tab layout where the user can search a book by title or by the user name, the aspect is shown in the next pictures:
In the new fragment, the user can choose the search by and can previsualize the matching results.
Which is the best way to implement something like this in Flutter, I understand that the beginning is something like this:
return Scaffold(
body: Column(
children: <Widget>[
// Page Content
],
),
appBar: AppBar(
title: Text(this.text),
actions: <Widget>[
IconButton(
onPressed: () {},
icon: Icon(Icons.search)
)
],
),
);
But how I should implement the tab bar to choose the search by and the search input text in the app bar to be focused.
Add this onPressed function
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
},
now create a new state class
return Scaffold(
appBar: AppBar(
title: TextField(),
bottom: TabBar(
tabs: [Text("Books"), Text("Users")],
),
actions: <Widget>[
IconButton(
onPressed: () {},
icon: Icon(Icons.search)
)
],
),
));
return Scaffold(
body: Column(
children: <Widget>[
// Page Content
],
),
appBar: AppBar(
title: Text(this.text),
bottom: TabBar(
tabs: [Text("Books"), Text("Users")],
),
actions: <Widget>[
IconButton(
onPressed: () {},
icon: Icon(Icons.search)
)
],
),
);
I have a home screen, there is a bottom tab bar with 4 bars. Now my concern is for the 1st tab bar.
There are different categories displayed in 1st tab bar for eg. as you can see in the screenshot there are 2 categories :
1) Category 1 (Motorcross, Road, and Accessories)
2) Popular categories
Now when I click on any of Category 1, I want the tab bar (4 tab bar) in the bottom but when I open the popular category I don't want that tab bar.
So I am stuck here.
My code snippet is below.
Scaffold(
backgroundColor: Colors.white,
body: GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: SafeArea(
top: true,
child: SizedBox.expand(
child: PageView(
physics: new NeverScrollableScrollPhysics(),
controller: _pageController,
onPageChanged: (index) {
setState(() => currentIndex = index);
},
children: <Widget>[
Products(),
News(),
Service(),
Events(),
],
),
),
),
),
floatingActionButton: FloatingActionButton(
elevation: 0,
child: Image.asset('assets/icons/bottom_center.png'),
backgroundColor: Colors.transparent,
focusElevation: 10,
disabledElevation: 10,
highlightElevation: 10,
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (BuildContext context) {
return WorldCategories();
}));
},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
onTap: (index) {
setState(() {
currentIndex = index;
_pageController.jumpToPage(index);
});
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit), title: Text("A")),
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit), title: Text("X")),
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit), title: Text("Y")),
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit), title: Text("Z")),
]),
);
and also floatingActionButton set to top on the second screen.
What is think is you can use the GestureDetector for the Popular categories text and on tap redirect it to your desired page.
GestureDetector(
onTap: () async {
// here you make your navigation for your desired page
Navigator.push(
context,
MaterialPageRoute(builder: (context) => youPage()),
);
},
child: Padding(
child: Text(
'Populat Categoreies',
),
))
Add two layouts inside products and when click motocross hide the 1st layout and display motocross layout and when clicking on popular categories
do a page navigation like
Navigator.push(context,
MaterialPageRoute(builder: (BuildContext context) {
return popularCategories();
}));
I've tried a lot, but I can't change the height of AlertDialog when I use Slider. I saw here on the Forum the suggestion to use ConstrainedBox. Did n't work. Is there a better way to show the Slider?
#override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: BoxConstraints(maxHeight: 100.0),
child: AlertDialog(
title: Text('Selecione a velocidade'),
content: Container(
child: Slider(
value: _fontSize,
label: _fontSize.round().toString(),
min: 20,
max: 200,
divisions: 18,
onChanged: (value) {
setState(() {
_fontSize = value;
});
},
),
),
actions: <Widget>[
FlatButton(
onPressed: () {
print('cancelar');
// Use the second argument of Navigator.pop(...) to pass
// back a result to the page that opened the dialog
Navigator.pop(context, _fontSize);
},
child: Text('Cancelar'),
),
FlatButton(
onPressed: () {
print('salvar');
// Use the second argument of Navigator.pop(...) to pass
// back a result to the page that opened the dialog
Navigator.pop(context, _fontSize);
},
child: Text('Salvar'),
),
FlatButton(
onPressed: () {
print('aplicar');
// Use the second argument of Navigator.pop(...) to pass
// back a result to the page that opened the dialog
Navigator.pop(context, _fontSize);
},
child: Text('Aplicar'),
),
],
),
);
}
I attached an image showing how AlertDialog looks.
You need to define the height for the Container which outside the Slider.
content: Container(
height:50, // define any height you want here
child: Slider(
This is how the output looked like.
Try this.
Dart pad to show your output
Let me know if it work out for you or not.
Code is here
#override
Widget build(BuildContext context) {
return FittedBox(
child: AlertDialog(
title: Text('Selecione a velocidade'),
content: Container(
child: Slider(
value: _fontSize,
label: _fontSize.round().toString(),
min: 20,
max: 200,
divisions: 18,
onChanged: (value) {
setState(() {
_fontSize = value;
});
},
),
),
actions: <Widget>[
FlatButton(
onPressed: () {
print('cancelar');
// Use the second argument of Navigator.pop(...) to pass
// back a result to the page that opened the dialog
Navigator.pop(context, _fontSize);
},
child: Text('Cancelar'),
),
FlatButton(
onPressed: () {
print('salvar');
// Use the second argument of Navigator.pop(...) to pass
// back a result to the page that opened the dialog
Navigator.pop(context, _fontSize);
},
child: Text('Salvar'),
),
FlatButton(
onPressed: () {
print('aplicar');
// Use the second argument of Navigator.pop(...) to pass
// back a result to the page that opened the dialog
Navigator.pop(context, _fontSize);
},
child: Text('Aplicar'),
),
],
),
);
}
}