Many flutter widgets forces their child to inherit their style, like:
ElevatedButton(
child: Text("Click Me."),
onPressed: (){},
);
this ElevatedButton() will force its Text() child to inherit a specific text color, weight and so on...
My question is how to make a widget that forces its child to inherit a style from it, and Thank you ^^.
I tried using Theme widget but it's useless.
as pskink mentioned in the comments DefaultTextStyle worked well.
Related
I want to show suggestion when cursor is on button or on some widget in flutter web
I share example how I want to show suggestion box but I don't know how to add suggestion box in flutter
You need to wrap widget with Tooltip see example.
flutter tooltip example
Try below code hope its help to you. Used Tooltip Widget
Refer Tooltip here
Test below code here
Tooltip(
message: "Managers",
child: ElevatedButton(
onPressed: () {},
child: Text('OK'),
),
),
Result Screen->
In addition to all the tooltip related recommendations, if they don't quite meet your requirements, there's OverlayEntry It allows to use any widget, but is not super easy to handle, so there's a couple packages out there that do some work with Overlays for you that you might consider.
https://pub.dev/packages/flutter_portal
https://pub.dev/packages/modals
To show overlay entry when hovering over some widget, wrap it with MouseRegion and use its onEnter and onExit methods to show and hide overlay
Can you help me solve this problem
Where the word beach should be at the bottom of the picture, but it does not go down
Use second widget of Stack as Expanded widget instead of Container widget:
Expanded(
child: Align(
alignement: FractionalOffset.bottom,
child: Text(.................)
))
You can switch the Image and container order in the Stack children's or better option you can use Positioned() widget to give the container that includes the text a specific position.
Flutter Dev videos:
https://youtu.be/liEGSeD3Zt8?t=49
https://youtu.be/EgtPleVwxBQ
flutterdartpostionedstackwidget
I am searching this topic and I must confess, I love the using function widgets for my applications. And in the my flutter experience, I never got any error or any unwanted result with this approach(I mean using function widgets).
But while my search, I couldn't totally understand the reason, why I must use the stateless widgets but not function widgets.
An example; I want to create a page, using scaffold, and appar.
My page must be statefull so I want to use
Scaffold scaffold({String pageTitle, Widget body, Widget floatingActionButton, Widget appBarLeading})=>Scaffold(
appBar: CustomAppBar(pageTitle: pageTitle, leading: appBarLeading),
body: body,
floatingActionButton: floatingActionButton,
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
backgroundColor: Colors.blueGrey[50],
);
this code and, my custom appbar coming from Stateless Widget.
So what happen if I use this structure for the beginning ?
İf I use the setstate, my appbar creating from to beginning or used from widget three ?
I can understand the reasons why must use stateless widget because it has final variables and this way, it is reused in the program behalf but What happen If I use stateless widgets in my function widgets ?
Please help me for understanding this topic.
Thank you very much.
I have some ListTile widgets around my app, and all of them have an icon.
From here I see that I need to override my ListTile with
ListTileTheme(
iconColor: Colors.blue,
child: ..
)
since the ListTile.iconColor is gray by default and doesn't fallback to ThemeData.iconTheme.iconColor.
I wonder if there is a way to specify the list tile theme in ThemeData, so I don't have to create a new widget just for that.
For now, there isn't, but this feature may arrive in the next flutter release: https://github.com/flutter/flutter/issues/31247
I'm learning Flutter and using the Shrine demo app ( https://codelabs.developers.google.com/codelabs/mdc-101-flutter/ ) they provide as a base for trying out other widgets.
I'm using the Shrine menu for navigation as an alternative to a Drawer.
I've got a few different routes/pages, and I want each to have their own FloatingActionButton that performs different functions on each of them, with no button on some of them, and maybe a BottomAppBar on some others.
In order to use a FloatingActionButton it needs to be passed as an argument to a Scaffold, but the Shrine Backdrop only has one Scaffold, which also holds the state for which menu option is selected.
If each page had its own Scaffold then this would be easy, but then I'd lose the cool menu that the Shrine app has.
How could I use the Shrine style menu with multiple different pages, each with their own unique FloatingActionButton or BottomAppBar?
Should I be moving menu state elsewhere? Should I somehow pass a button action from the child widget back up to the Backdrop's Scaffold (if so, how)? Should I give up and use a Drawer?
Instead of using the FloactingActionButton property in a Scaffold, you can position the button at the bottom right of your pages with the 'Positioned' widget in individual pages.
For example:
body: Stack( // must add Stack widget
chidren: <Widget> [
.
.
. // your other widgets on this page
.
Positioned(
right: 10,
bottom: 10,
child: FloatingActionButton(
onPressed: () => yourFunction,
),
child: Icon(Icons.add),
backgroundColor: Colors.red,
),
),
],
);
Hope this helps :)