I'm trying to create a navigation drawer in my flutter app,however i want it to have a circle avatar image as icon instead of the default tree horizontal lines. Please is there a way to acheive this?? Any help is appreciated
leading: Builder(
builder: (BuildContext context) {
return IconButton(
// icon: const Icon(Icons.access_alarm_rounded),
icon: Container(
child: Hero(
tag: 'Profile Picture',
child: CircleAvatar(
backgroundImage: NetworkImage(
'googleUserUrl'),
),
),
),
onPressed: () {
Scaffold.of(context).openDrawer();
},
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
);
},
),
You should first google how to achieve this, then try it out yourself. If you encounter errors that you can't resolve by yourself, then you should come here to ask questions.
I will provide you some links or post to help you.
First, follow this post to learn how to add image to your project.
Then, this is the official documents for getting a circle avatar. Also, this is an already answered question about this issue
First of all, there are a lot of resources to help you this you may find out google to achieve this let me share some its up to you what image you want asset_Image or
network_image then you use this image into appbar widget takes action_widget as an argument and then use popupmenuButton and then use clipoval
Example
actions: <Widget>[
PopupMenuButton<String>(
icon: Container(
child: ClipOval(
child: Align(
heightFactor: 1,
widthFactor: 1,
child: Image.network(googleUserUrl),
),
)
),
Related
I have a BottomAppBar that has a FloatingActionButton. However, I only want this button to be seen in one particular screen. In the best case, I'd like to add this button only when the user clicks on that particular screen.
I've found that you can add a FAB like this:
return Scaffold(
extendBodyBehindAppBar: true,
extendBody: true,
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
floatingActionButton: FloatingActionButton(
onPressed: () {
...
},
child: const Icon(
Icons.add_sharp,
color: Color(0xFFFFFFFF),
),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: buildBottomNavigationBar(),
);
However, as you can see this Scaffold is shared by all the screens that can be selected in the bottomNavigationBar. How do I add a FAB only for a particular screen?
I'd like the FAB to be embedded into the bottomNavigationBar so I do not want to add a plain button to that particular screen. Thanks.
The answer by #Josip Domazet is absolutely right, but it can be achieved with shorter workaround instead of creating different Scaffold, using conditional operator as
floatingActionButton: _selectedIndex==1
? FloatingActionButton(....) : const SizedBox.shrink(),
Use Stack In your Specific Tab and Add FAB at the bottom :
Example :
Stack(
children[
Container(height: double.infinity,
width: double.infinity) // for full screen
Position(
bottom : 10,
left: 150,
right : 150,
child: FloatingActionButton(
onPressed: () {
...
},
child: const Icon(
Icons.add_sharp,
color: Color(0xFFFFFFFF),
),
)
)
])
Wrap that specific screen with scaffold again and use fab on that screen only.
Turns out the solution was actually quite simple and I was overthinking stuff. I have a variable that keeps track of the currently open screen. So I simply added this little logic to the mother screen that hosts the bottomNavigationBar:
if (_selectedIndex==1){
// Other screen that needs the FAB
return Scaffold(
...,
floatingActionButton: FloatingActionButton(
....
),
bottomNavigationBar: buildBottomNavigationBar(),
);
}
return Scaffold(
...,
bottomNavigationBar: buildBottomNavigationBar(),
);
I am new in flutter.
I am following some YouTube videos to learn flutter. After adding a picture in card(home screen) now I want to add two buttons below that picture. how can i do it.
the picture Adding code
body: Center(
child: Card(
child: Column(
children: [Image.asset("assets/image-name")],
),
),
),
Here you have a great page, where you can find implementations of basic material widgets in Flutter.
For your example, it would look like this:
body: Center(
child: Card(
child: Column(
children: [
Image.asset("assets/image-name"),
ElevatedButton(
onPressed: () {
// Respond to button press
},
child: Text('CONTAINED BUTTON'),
)
],
),
),
),
For a second button, you can just add another one in the children array.
You can also wrap both buttons in Row widget, that will allow you to place them horizontally, next to each other.
i am created an SVG image for background, but it is loaded after some time, the issue is:
when it is not loaded yet all widgets appears randomly. i just need a loader after the image loaded it page widget appears.
the code is:
Scaffold(
appBar: const _CustomNotificationAppBar(),
body: isFinished
? SingleChildScrollView(
child: Stack(
children: [
//notification background
Opacity(
opacity: 0.42,
child: SvgPicture.asset(
'assets/images/notification_background.svg',
),
),
IconButton(
icon: const Icon(
Icons.notifications_active_outlined,
),
onPressed: () {})),
],
),
)
: const Center(
child: CircularProgressIndicator(),
),
);
well if I understands you well and as long as your SVG is loading from the device "asset",
there should not be delay in first place.
I think the problem is you emulator or physical device is too slow , And you may face this problem in debug only
try to run flutter build APK and install that generated APK in your phone and check if problem remains.
however you can achieve that also like this
SvgPicture.asset(
'assets/images/notification_background.svg',
placeholderBuilder: (context) => Text("I am Loading"),
),
You can wrap it in a Container, and it will work.
For eg:
Container(
//height :desired height,
//width : desired width
child: Opacity(
opacity: 0.42,
child: SvgPicture.asset(
'assets/images/notification_background.svg',
),
))
You can pass a placeholderBuilder to your SvgPicture.asset like this:
SvgPicture.asset(
'assets/images/notification_background.svg',
placeholderBuilder: (context) => Icon(Icons.your_desired_icon),
),
You can also wrap the Icon with a SizedBox if you need to comply with a certain size, or replace it by any other widget that you wish.
More info about the widget you're using is available in its API docs.
So I'm searching for a Menu often found in a Settings Screen. It's used to select a Setting.
It opens when you press on a ListTile and then it fills the mayority of the Screen, while the borders are transparent. In the menu you have to select one of the options.
An example usecase of that would be to select a Language(onTap of the ListTile opens a Menu where you can select between all the avaliable languages)
It is similar to that of a PopupMenuButton, however as already mentioned it fills most of the screen, and the individual selectable items have a radiobutton in front of the text(probably RadioListTiles)
I hope someone gets what I'm talking about, because for the past 3 hours I'm searching for this widget but just find articles about the PopupMenuButton over and over.
Edit: I finally found an app that uses the feature I'm looking for
: https://imgur.com/a/A9k71io
By clicking on the first ListTile in the first Picture, the dialog in the second picture opens up.
Hopefully this custom widget is something roughly what you want, try to copy and paste it in your project and play with it.
this is made using the Dialog widget, to exit the Dialog you can tap out of it/ press the device back arrow and I added a small back icon on the top left corner.
tell me if it helped :)
class TestPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
final deviceSize = MediaQuery.of(context).size;// the device size
return Scaffold(
body: Center(
child: ListTile(
tileColor: Colors.grey[300],
title: Text(
'Language',
style: TextStyle(fontSize: 25),
),
onTap: () => showDialog(
context: context,
builder: (context) => Dialog(
insetPadding: EdgeInsets.all(20),
child: Container(
color: Colors.white,
height: deviceSize.height,
width: deviceSize.width,
child: Column(
children: [
Row(
children: [
IconButton(
color: Colors.red,
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop(),
),
],
),
Spacer(),
Text('Pick A Language'),
Spacer(),
],
),
),
),
),
),
),
);
}
}
I saved the google logo a as .png because I want to keep its colors. I am aware there are some packages for predefined sign-in buttons like google or with the google Icon(but I can't keep the colors obviously in this case), but I would like to know if I can somehow make so the .png image acts like an Icon.
You can use whatever button widget you like or you can create your custom button...
According to your image you can use outline button or flat button... then in your child parameter add Row with image and text
OutlineButton(child: Row(children: Image.asset(your_image_location), Text('Sign in with Google')))
body: Stack(
children: <Widget>[
Center(
child: IconButton(
icon: Image.asset('path/the_image.png'),
iconSize: 50,
onPressed: () {},
)
Positioned(
child: Container(
child: Center(child: Text('Sign in With Google')),
)),
],
)