Related
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.
I tried to put a border to a container like this code:
Container(
padding: EdgeInsets.all(15.sp),
decoration: BoxDecoration(
// color: Colors.yellow,
border: Border.all(
color: kPrimaryColor,
width: 7,
style: BorderStyle.solid,
),
),
child: QrImage(
data: controller.generatedCode,
version: QrVersions.auto,
size: 300.0,
),
),
The code above gives me a complete border
the border of the QR code, I want to implement a border like it
Try this. It will work.
Container(
child: Text(
'This is a Container',
textScaleFactor: 2,
style: TextStyle(color: Colors.black),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(color: Colors.green, spreadRadius: 3),
],
),
height: 50,
),
I found it, using dotted_border package:
Widget get customBorder {
Path customPath = Path()
..moveTo(0, 0)
..lineTo(0, 25)
..moveTo(0,0)
..lineTo(25, 0)
..moveTo(75,0)
..lineTo(100,0)
..lineTo(100,25)
..moveTo(0,75)
..lineTo(0, 100)
..lineTo(25, 100)
..moveTo(100,75)
..lineTo(100, 100)
..lineTo(75,100)
;
return DottedBorder(
customPath: (_) => customPath,
color: Colors.indigo,
dashPattern: [1, 1],
strokeWidth: 2,
child: Container(
height: 100,
width: 100,
color: Colors.green.withAlpha(20),
),
);
}
I need to draw a rounded border in just one side of a container. The problem is that this approach:
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(4.sp), bottomRight: Radius.circular(4.sp)),
border: Border(bottom: BorderSide(width: 2.sp, color: Color.fromARGB(255, 237, 237, 237))),
),
throws this error:
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during paint():
flutter: A borderRadius can only be given for a uniform Border.
flutter: The following is not uniform:
flutter: BorderSide.color
flutter: BorderSide.width
flutter: BorderSide.style
How can I achieve that? Expected output:
Add a container with Box Shadow like this:
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.shade100,
spreadRadius: 1,
blurRadius: 0,
offset: Offset(0, 0), // changes position of shadow
),
],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
),
),
)
Seems that it's not supported in Flutter yet.
You can do what you need through an stack (wash your hands after using this code, though):
Stack(children: [
Container(
width: double.infinity,
height: 8.sp,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4.sp)),
border: Border.all(width: 2.sp, color: Color.fromARGB(255, 237, 237, 237)),
),
),
Container(
width: double.infinity,
height: 3.sp,
color: Colors.white, //or your bg color
),
])
The tab bar with a custom tab indicator created by changing the tabs container decoration as shown below. Its works nicely when changing the tabs with tap on the tab bar. But when changing the tabs using swipe left/ right action manually slowly, I could see the tab bar changing to new decoration with a weird UI rendering.
tabBar() => TabBar(
isScrollable: false,
controller: tabController,
labelPadding: EdgeInsets.zero,
indicator: BoxDecoration(
color: myAccentColor, borderRadius:12),
tabs: tabs(),
);
tabs() => [
Container(
height: tabHeight,
decoration: BoxDecoration(
color: tabIndex == 0 ? Colors.transparent : Color(0xffF7F7F7),
border: Border(
right: BorderSide(
width: 1.0, color: Colors.black.withOpacity(0.1)),
),
),
child: Center(
child: Text(
"Trending",
style: Theme.of(context).textTheme.subtitle2.copyWith(
color:
tabIndex == 0 ? Colors.white : V2Colors.darkColor292929),
))),
Container(
height: tabHeight,
decoration: BoxDecoration(
color: tabIndex == 1 ? Colors.transparent : Color(0xffF7F7F7),
border: Border(
right: BorderSide(
width: 1.0, color: Colors.black.withOpacity(0.1)),
),
),
child: Center(
child: Text(
"My Feed",
style: Theme.of(context).textTheme.subtitle2.copyWith(
color:
tabIndex == 1 ? Colors.white : V2Colors.darkColor292929),
))),
Container(
height: tabHeight,
color: tabIndex == 2 ? Colors.transparent : Color(0xffF7F7F7),
child: Center(
child: Text(
"My Topics",
style: Theme.of(context).textTheme.subtitle2.copyWith(
color:
tabIndex == 2 ? Colors.white : V2Colors.darkColor292929),
))),
];
Any direction towards a better approach is appreciated.
Inside your tabs() method, set all the Tabs color as Transparent (Your Containers).
Instead of this
decoration: BoxDecoration(
color: tabIndex == 1 ? Colors.transparent : Color(0xffF7F7F7),
border: Border(
right: BorderSide(
width: 1.0, color: Colors.black.withOpacity(0.1)),
),
),
Use
decoration: BoxDecoration(
color: Colors.transparent,
border: Border(
right: BorderSide(
width: 1.0, color: Colors.black.withOpacity(0.1)),
),
),
Note: Try to make a CustomWidgets wherever possible. For examples You
Items in the tabs() method can be a Custom Widget. For ex:
CustomTabWidget
I am getting a warning when using following code but my app is running fine:
════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during paint():
A borderRadius can only be given for uniform borders.
'package:flutter/src/painting/box_border.dart':
Failed assertion: line 510 pos 12: 'borderRadius == null'
Here is my code:
Container(
height: screenSize.height*.13,
width: AppSize.medium,
decoration: BoxDecoration(
color: Colors.red,
border: Border(
right: BorderSide(
width: 1.0,
color: Colors.blue
),
),
borderRadius: BorderRadius.only(
topRight: Radius.circular(AppSize.small),
bottomRight: Radius.circular(AppSize.small),
)
),
)
This is the easiest way that I could came up with... as you can see there's 2 container, the color of outer container is actually the color of the border and the margin of inner container is the strokeWidth of the border and the color of inner container is the background color.
Container(
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(15.0),
topRight: const Radius.circular(15.0),
),// BorderRadius
),// BoxDecoration
child: Container(
margin: const EdgeInsetsDirectional.only(start: 2, end: 2, top: 2),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(13.0),
topRight: const Radius.circular(13.0),
),// BorderRadius
),// BoxDecoration
),// Container
),// Container
It's a bit silly answer but works! ;)
Container(
decoration: new BoxDecoration(
gradient: new LinearGradient(
stops: [0.02, 0.02],
colors: [Colors.red, Colors.white]
),
borderRadius: new BorderRadius.all(const Radius.circular(6.0))))
Flutter is complaining because you only apply a right border to your container, but want to have a border radius as well.
Flutter expects the border to be uniform, i.e. all the way around and in the same color, when applying border radius. If you jump to the sources where the assertion error was thrown you can have a look at the actual assertion.
I was struggling with this same error, and found out a simpler solution that's much simpler than the alternatives suggested, which is using a shadow instead of a border.
If you think about it a 1pt border on one side is exactly the same as a shadow without blur that's offset 1pt in that direction.
You can create your Container with the round borders and use decoration to add a shadow to act as your desired border. Here's an example simulating a bottom border:
Container(
padding: EdgeInsets.symmetric(horizontal: 32.0, vertical: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(46),
boxShadow: [
BoxShadow(
color: Color(0xFFEEEEEE),
blurRadius: 0,
offset: Offset(0, 1),
),
],
),
child: ...
),
All to this effect:
Container(
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.only(
topRight:
widget.currentJobIndex == 0 ? Radius.circular(7) : Radius.zero,
topLeft:
widget.currentJobIndex == 0 ? Radius.circular(7) : Radius.zero,
),
),
child: Container(
padding: EdgeInsets.only(top: 17, bottom: 20, left: 12, right: 12),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: AppColors.greyE5))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("This is the brief job description"),
SizedBox(height: 10),
Row(children: [
Text(
"Budget",
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(":30,000"),
Spacer(),
Text(
"Total Bids",
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(":32",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).primaryColor))
]),
SizedBox(height: 10),
Row(children: [
Text(
"Status: Confirmed",
style: TextStyle(color: Theme.of(context).primaryColor),
),
Spacer(),
Text(
"Monday August 22, 2021",
style: TextStyle(fontSize: responsiveSize(10, context)),
),
])
],
),
),
)
I used two containers, the outer one has the border radius, while the inner one has only bottom border. This way Flutter will no longer complain
Flutter expects the border to be uniform means all the way around and in the same color when applying border radius.
Check your border color are you applying the same on all sides?
Either you can apply the different color without a radius or you can use the same color with a different radius
This is the only solution that is not a workaround. Wrap your widget inside a ClipRect with an border on all sides:
ClipRect(
clipper: Customshape(),
child: Container(
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(Radius.circular(5)),
),
),
),
This CustomShape Clipper cuts the border on the left side, which is why the Offsets x value is 2. If you need to clip it on the right side, then set x to 0 and use "size.width - 2".
class CustomShape extends CustomClipper<Rect>{
#override
Rect getClip(Size size) => const Offset(2.0, 0) & Size(size.width, size.height);
#override
bool shouldReclip(covariant CustomClipper<Rect> oldClipper) => true;
}