How to add youtube player in a modal bottom sheet flutter? - flutter

I am using youtube_player_flutter in a project, I need to implement this in a modal bottom sheet. How can I implement this?

Try the following code:
showModalBottomSheet(
context: context,
builder: (context) => Scaffold(
body: YoutubePlayer(…),
),
),

Related

I want a similar screen (one on top of other) like following to complete my weather app made using flutter . Can anyone please help me out?

I want this type of screen one on top of other and the previous screen should be lightly blurred or it should slightly darkens
You could use 'ModalBottomSheet' or even 'DraggableScrollableSheet' if a list is associated.
ModalBottomSheet
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
// widgets
),
);
});
DraggableScrollableSheet
DraggableScrollableSheet(
builder:
(BuildContext context, ScrollController scrollController) {
return Container(
// widgets
);
},
),

Unable to Display CupertinoDialog in Flutter

I have the following code to display Cupertino AlertDialog but I keep getting an error:
showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
title: Text("Attention"),
content: Text(this),
actions: [
CupertinoDialogAction(
isDefaultAction: true,
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
);
Here is the error I keep getting
Unhandled Exception: No MaterialLocalizations found.
I thought CupertinoAlertDialog has nothing to do with MaterialApp, so why do I keep getting this error.
The parent app here is a CupertinoApp.
How do I fix this?
ShowDialog displays a Material dialog above the current contents of the app, with Material entrance and exit animations, modal barrier color, and modal barrier behavior (dialog is dismissible with a tap on the barrier).
So, Basically to show a Cupertino dialog you can use
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(),
);

How to pop CupertinoPageRoute with swipe down?

Currently I'm using the following Code to get a FadeInTransition from the bottom when opening the page.
Navigator.of(context).push(
CupertinoPageRoute(
fullscreenDialog: true,
maintainState: true,
builder: (BuildContext context) => Routines(),
)
)
Normally in iOS you can just swipe left to close the current page. Is there an easy way to swipe down to pop the current page or do I have to implement a custom field with a GestureDetector()?
The goal is to have a closing transition like in the GIF below using a swipe down at the top
I considered using a DraggableScrollableSheet but I don't want to slide the Page into view from the bottom.
I ended up solving it with an DraggableScrollableSheet:
onPressed: () {
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return Routines();
},
);
},
and Wrapping my new Page with:
return DraggableScrollableSheet( //TODO make same for Entries
expand: false,
initialChildSize: 1.0,
minChildSize: 0.8,
builder: (context, scrollController) {
return Page2();
}
);

Flutter & AlertDialog : How do I align my AlertDialog to the bottom of the screen?

Flutter & AlertDialog : How do I align my AlertDialog to the bottom of the screen?
AlertDialog normally appears in the middle of the screen. How do I put it at the bottom of the screen?
showDialog(
return AlertDialog(
content : Container()
);
)
Why do you want to use showdialog? To pop a section from the bottom of the screen you need to use bottom sheet behavior with the showBottomSheet method. Here is how to use the bottom sheet:
showBottomSheet(context: context, builder: (BuildContext context){
return Container(
child: ListView(
children: [
ListTile(title: Text('title 1'),),
ListTile(title: Text('title 2'),),
ListTile(title: Text('title 3'),),
],
),
);
});
I recommend you to use the flutter_modal_bottom_sheet plugin. This plugin provides lots of bottom sheet behavior for both Material and Cupertino design. For example :
After installing the plugin you can use it like this for material design:
showMaterialModalBottomSheet(
context: context,
builder: (context, scrollController) => Container(),
)
Or for ios Cupertino design:
showCupertinoModalBottomSheet(
context: context,
builder: (context, scrollController) => Container(),
)

How to make CupertinoActivityIndicator top of every layout?

How to make CupertinoActivityIndicator top of every layout?
i need to show progress bar on when login and home page loading time
You could show a dialog like this:
void _showIndicator() {
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => Center(
child: CircularProgressIndicator(),
),
);
}
In this example, I am using CircularProgressIndicator, but you could replace that with CupertinoActivityIndicator. When you want to dismiss the indicator, call:
Navigator.pop(context);