How do I Reverse RoundBottom in Appbar Flutter - flutter

I tried to use the Radius.Circular method and I input a minus value, but it doesn't seems to work at all.
Is there a method to do it?
Screenshot

Oh, flutter does use constraints to restrict the AppBar height, in this case the constraint is hardcoded to 56 according to material design guidelines. To make your AppBar like that the only thing that occurs to me is to have your Scaffold's Body like this
body:Container(
color: Colors.lightBlue,
child: Container(
color: Colors.white,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(100), topRight: Radius.circular(100))),
child: Center(
child: Text('Zero'),
),
),
)
We are making the background the same color as the appBar to make that effect. You could also use Stack to achieve the same effect.

You can do this. Make Scaffold background color same as AppBar background color, set elevation to 0 in AppBar and in body use container with border radius.
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
title: Text(
'Home',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
),
elevation: 0,
automaticallyImplyLeading: false,
backgroundColor: Colors.black,
brightness: Brightness.dark,
),
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24)),
color: Colors.white),
child: Container()));
}

Related

Flutter borders

Hello I very new to Flutter and I am trying to create a button, but I have a problem with this.
This is the code:
Align(
alignment: AlignmentDirectional(-0.03, 0.13),
child: FFButtonWidget(
onPressed: () {
print('Login pressed ...');
},
text: 'Login',
options: FFButtonOptions(
width: 130,
height: 40,
color: FlutterFlowTheme.of(context).primaryColor,
textStyle: FlutterFlowTheme.of(context).subtitle2.override(
fontFamily: 'Poppins',
color: Colors.white,
),
borderSide: BorderSide(
color: Colors.transparent,
width: 1,
),
borderRadius: BorderRadius.circular(8),
),
),
),
This is the error:
The argument type 'BorderRadius' can't be assigned to the parameter type 'double?'.
Do you have any suggestion?
I think you are using FlutterFlow.
Here you don't need to give the border radius like this
borderRadius: BorderRadius.circular(8)
Do it like this
borderRadius: 8
This is because FlutterFlow button widget is not like the usual Flutter button widget. They are modified versions of actual Flutter widgets.
In your case, properties of FFButtonWidget is set using this class
FFButtonOptions()
This class probably takes borderRadius as a double value and internally sets it like this
borderRadius: BorderRadius.circular(8)
So you have to give the required borderRadius as a double value.
The borderRadius field in the FFButtonOptions require a double parameter. Try
borderRadius: 8.0
It is hard to say, because I do not know how the FFButtonWidget looks like. Normally, your way of setting the border radius would be good for material widgets, for instance:
Align(
alignment: AlignmentDirectional(-0.03, 0.13),
child: Container(
width: 130,
height: 40,
decoration: BoxDecoration(
color: FlutterFlowTheme.of(context).primaryColor,
borderRadius: BorderRadius.circular(8),
),
child: TextButton(
onPressed: () {
print('Login pressed ...');
},
child: Text('Login'),
style: ButtonStyle(
textStyle: FlutterFlowTheme.of(context).subtitle2.override(
fontFamily: 'Poppins',
color: Colors.white,
),
),
),
),
),
Probably the FFButtonWidget takes a double parameter and finally transforms it into
borderRadius: BorderRadius.circular(8.0)
But if you want to use material widgets, you can check how the buttons work in Flutter here.

Flutter transparent button elevation

I created a custom button that I want to give a color and an elevation. Works finde, except when I give the button the color Colors.transparent. Here is an example to showcase my problem:
Widget buildButton(void Function() onPressed, String label, double? elevation) {
return OutlinedButton(
onPressed: onPressed,
child: Text(label),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.white,
side: BorderSide(
width: 2,
color: Colors.blue,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
elevation: elevation ?? 0
),
);
}
class ButtonsDemo extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
buildButton(() {}, "Button", null),
buildButton(() {}, "Button", 5),
],
),
),
);
}
}
The buttons look like this:
Here is how they should look like (I set the color of the buttons to the background color of the screen to showcase them, but I can't do that in my code):
I tried this answer but it only got me so far (I don't know if I did it completely wrong, but it looks so):
I also tried this answer and it got me there:
So, as you can see, both of them answers haven't helped me at all. Can anyone show me how I can add elevation to a transparent button?
The best solution to your problem is to use ElevatedButton instead of OutlinedButton and to give it a shadowColor. The code below is for the second button, please give it a try.
ElevatedButton(
onPressed: () {},
child: Text(
'Elevated',
style: TextStyle(color: Colors.black),
),
style: ElevatedButton.styleFrom(
elevation: 5,
primary: Colors.transparent,
shadowColor: Colors.transparent.withOpacity(0.1),
side: BorderSide(
width: 2,
color: Colors.blue,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),

Flutter: AppBar shape (rounded top corners with different background for toolbar and appbar)

I need to achieve something like this:
AppBar - my target
I tried using border radius
Widget build(BuildContext context) {
final _appBar = AppBar(
elevation: 6.0,
shape: ContinuousRectangleBorder(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(90.0),
),),
title: Text(listPagesNames[_cIndex]),
);
But it changed the left top corner at the level of the tool bar. And not by much (even though I set radius at 90.0)
Using border radius
And I thought, well maybe I can change the size.
Because I can change the background color of tool bar using services package:
import 'package:flutter/services.dart';
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: kMainRedPalette,
));
But using the size, the ApBar still 'starts' at the same place.
I thouht maybe something with offset (because I can already change the toolbar color), but I'm not sure how can I ofset appBar (and if it is possible at all).
I'm new to dart, so any idea will be helpful :)
Something like this??
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() async {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.red,
));
runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MyApp()));
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: AppBar().preferredSize,
child: SafeArea(
child: Container(
color: Colors.red,
child: AppBar(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
topRight: Radius.circular(25.0)
)
),
elevation: 8,
backgroundColor: Colors.white,
leading: Icon(Icons.menu, color: Colors.black,),
),
),
),
),
body: Container(color: Colors.white,),
);
}
}
#Will Hlas answer solves my problem :)
If anyone will need to use "tapable" leading icon as e.g. drawer opener, remember to wrap Icon in IconButton widget and place it into another Builder (just like in code below; code based on Will's answer).
appBar: PreferredSize(
preferredSize: AppBar().preferredSize,
child: SafeArea(
child: Container(
color: Colors.red,
child: AppBar(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
topRight: Radius.circular(25.0),
),
),
elevation: 8,
backgroundColor: Colors.white,
leading: Builder(
builder: (context) => IconButton(
icon: Icon(
Icons.menu,
color: Colors.black,
),
onPressed: () {
Scaffold.of(context).openDrawer();
},
tooltip:
MaterialLocalizations.of(context).openAppDrawerTooltip,
),
),
title: Text('Text on AppBar',
style: TextStyle(color: Colors.black),
),
),

How to change border color and width of OutlineButton globally?

I need to change the border color and width of the OutlineButton, I know one way of doing this by directly mentioning it inline as below:
OutlineButton(
child: Text('SIGN IN'),
padding: EdgeInsets.all(8.0),
onPressed: handleSignIn,
borderSide: BorderSide(
color: Colors.white, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 1, //width of the border
),
)
If I do it as mentioned below, it's effecting FlatButton and RaisedButton and this is NOT effecting OutlineButton.
MaterialApp(
title: 'MyApp',
theme: ThemeData(
buttonTheme: ButtonThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
// this effects to FlatButton and RaisedButton
side: BorderSide(
color: Colors.white, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 1, //width of the border
),
),
),
),
);
So, How to change border color and width ONLY of OutlineButton globally (through out the app)?
I don't think you can do for that in OutlineButton. So, what i can suggest you is to create a global theme data in a global file.
var borderData=BorderSide(
color: Colors.white, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 1, //width of the border
)
Then you can easily use it any class just by importing that global file.
OutlineButton(
child: Text('SIGN IN'),
padding: EdgeInsets.all(8.0),
onPressed: handleSignIn,
borderSide: borderData,
)
This will reduce your boiler plate code in your case.
Unless borderSide is explicitly added to the OutlineButton, it will default to a width of 1.0, a style of solid and this color:
Theme.of(context).colorScheme.onSurface.withOpacity(0.12)
You have the option of changing onSurface of your app theme, but that will affect other widgets as well.
You can do what Jay suggested in the other answer, but my preference would be to create a different widget. This way, if you ever want to change anything else to all of your OutlineButtons in the future, you only need to change your custom widget:
import 'package:flutter/material.dart';
class OutlineButton2 extends OutlineButton {
const OutlineButton2({
Key key,
#required VoidCallback onPressed,
Widget child,
}) : super(
key: key,
onPressed: onPressed,
child: child,
borderSide: const BorderSide(
color: Colors.white,
style: BorderStyle.solid,
width: 1,
),
);
}
This class is deprecated, please use OutlinedButton instead
OutlinedButton(
style: TextButton.styleFrom(
primary: primaryColor,
side: BorderSide(color: primaryColor),
minimumSize: Size(200, 50),
),
child: Text('SIGN IN'),
),
try deleting the OutlineButton
Try the code below:
GestureDetector(
child: Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border(
top: BorderSide(
width: 2.0,
color: Theme.of(context).primaryColor)),
),
child: Text('SIGN IN'),
),
onTap: onPressed,
),
basically the GestureDetector will take the onPressed logic code and the container is gonna give the decoration as you ask from it with the Text inside

Tooltip message text and background color

I have Image.asset wrapped on Tooltip
Padding(
padding: edgeInsets,
child: Tooltip(preferBelow: false, message: "Miejsca parkingowe ogólnodostępne", child: Image.asset("assets/icons/garage.png", width: _iconSize, height: _iconSize,)),
),
How to set tooltip message text color and background color?
ToolTip supports the decoration named argument, so you don't need to change your top-level theme.
/// Specifies the tooltip's shape and background color.
///
/// If not specified, defaults to a rounded rectangle with a border radius of
/// 4.0, and a color derived from the [ThemeData.textTheme] if the
/// [ThemeData.brightness] is dark, and [ThemeData.primaryTextTheme] if not.
final Decoration decoration;
However, there are other widgets, that include the ToolTip widget in their build method, for example, IconButton where they only support a tooltip as a String, so there's no way currently to change the tooltip style for the IconButton
You can change color of tootip with textStyle attribute. and background color of tooltip with decoration attribute.
Padding(
padding: edgeInsets,
child: Tooltip(textStyle: TextStyle(color: Colors.white),decoration: BoxDecoration(color: Colors.red),text preferBelow: false, message: "Miejsca parkingowe ogólnodostępne",
child: Image.asset("assets/icons/garage.png", width: _iconSize, height: _iconSize,)),
),
I think, Tooltip does'not provide a parameter to change these behaviors but
Tooltip takes the your theme
final ThemeData theme = Theme.of(context);
final ThemeData darkTheme = ThemeData(
brightness: Brightness.dark,
textTheme: theme.brightness == Brightness.dark ? theme.textTheme : theme.primaryTextTheme,
platform: theme.platform,
);
so you can create theme in your MaterialApp (Text color works but backgroundColor does'not work in my app, you can give a try)
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
backgroundColor: Colors.amber,
primaryTextTheme: TextTheme(
body1: TextStyle(
color: Colors.blue,
)
),
primarySwatch: Colors.blue,
),
home: ......
or
This is Tooltip code may be you can change from the source code of the Tooltip which is an bad solution.
return Positioned.fill(
child: IgnorePointer(
child: CustomSingleChildLayout(
delegate: _TooltipPositionDelegate(
target: target,
verticalOffset: verticalOffset,
preferBelow: preferBelow,
),
child: FadeTransition(
opacity: animation,
child: Opacity(
opacity: 0.9,
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: height),
child: Container(
decoration: BoxDecoration(
color: darkTheme.backgroundColor,
borderRadius: BorderRadius.circular(2.0),
),
padding: padding,
child: Center(
widthFactor: 1.0,
heightFactor: 1.0,
child: Text(message, style: darkTheme.textTheme.body1),
),
),
),
),
),
),
),
);
You can create a TooltipThemeData and set it into your top-level ThemeData.
TooltipThemeData(
textStyle: TextStyle(
color: Colors.white,
fontFamily: "Questrial",
fontWeight: FontWeight.bold,
),
decoration: BoxDecoration(
color: Colors.indigo,
borderRadius: BorderRadius.circular(20),
),
);
It's possible set the color of an individual icon's tooltip by setting TooltipTheme as the parent widget, for example as follows:
TooltipTheme(
data: TooltipThemeData(
textStyle: TextStyle(fontSize: 15, color: Colors.white),
decoration: BoxDecoration(
color: Colors.blue[300],
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
),
child: IconButton(
tooltip: 'Icon Title',
icon: Icon(Icons.analytics, color: Colors.black, size: 50),
onPressed: () {}
),
)
As per the documentation.