I'm trying to create a bottom navigation bar like the Twitter app has, but I can't find how to customize the highlightShape size.
I can customize corners, colors but not size, I would like to make same size which exceed the bounds of the widget like splash in my builder.
Here is how look my bottom navigation button. Thank you! for help in advance.
Center(
child: Ink(
height: height,
width: width,
child: InkResponse(
splashFactory: InkRipple.splashFactory,
radius: radiusSize,
onTap: () {
const int itemIndex = 1;
_onTapped(itemIndex);
},
child: _pageIndex == 1
? Icon(OMIcons.favoriteBorder, color: Colors.black, size: 28.0)
: Icon(OMIcons.favoriteBorder, color: Colors.grey[600]),
),
),
),
This may be an old question but, the "max" radius should match the normal radius if no radius property is specified.
To change the normal radius you should create a custom splashfactory , https://stackoverflow.com/a/51116178/10205629 .
Or as a little hack you could copy the source code and create your own inkresponse modifying the values
Related
I am unable to change font size for button text for apple sign-in. Is there a way to decrease the size. I tried using text widget but I am unable to assign Text widget to String. I know we can build a button from scratch but is there an efficient way?
Package I am using: https://pub.dev/packages/the_apple_sign_in
I tried changing container width and height but text size remains same
Code for apple sign-in button:
if (appleSignInAvailable.isAvailable)
Container(
height:
(1 / 20) * MediaQuery.of(context).size.height, //20,
width:
(1 / 1.6) * MediaQuery.of(context).size.width, //20,
child: AppleSignInButton(
//type: ButtonType.signIn,
style: ButtonStyle.black,
//buttonText: '' ,
//style: ButtonStyle, // style as needed
type: ButtonType.signIn, // style as needed
onPressed: () => _signInWithApple(context),
),
),
I'm trying to recreate this:
I've tried with a PageView.builder, and got this far (sorry for the ugliness of colors but it's for visualization purposes):
This is the Code:
Container(
height: 40 * 2 + 100.0,
child: PageView.builder(
scrollDirection: Axis.horizontal,
controller: controller,
itemCount: 9,
itemBuilder: (context, index) {
double value = 1.0;
try {
value = controller.hasClients
? controller.page - index
: 1.0;
} catch (e) {
value = 1.0;
}
value = value.abs().clamp(0.0, 1.0);
value = 1 - value;
return Padding(
padding: EdgeInsets.symmetric(horizontal: 6.0),
child: Container(
width: value == 1.0 ? 80.0 : 60.0,
height: 30.0,
color: Color.lerp(Colors.green,
Colors.red, value),
child: Center(
child: Text(
index.toString(),
style: TextStyle(
color: Color.lerp(
Colors.red, Colors.black, value),
fontSize: lerpDouble(20.0, 40.0, value)),
)),
),
);
},
))
And the controller variable is this:
controller = new PageController(initialPage: 5, viewportFraction: 1/4);
controller.addListener(() {
setState(() {});
As you can see I managed to change the color and textSize to the "selected" item (the red ones), but even If I try to set its size to be bigger, it has no effects. I tried with a ListView.builder which made me set different sizes but with it I didn't have page Snapping and a default initial Page, so I opted out.
hope everything is clear.
Is it possible to do it, and if it is, how Could I do it?
I know its an old question but you can change width and height by changing margin of the container. You have to basically change a container (this one inside the Padding widget) margins values by value of your "value" variable and also I would highly suggest using AnimatedContainer for out of the box animations. Add this code to your container:
EdgeInsets.only(bottom: 50, right: value == 1.0? 20 : 40, left: value == 1.0? 20 : 40, top: value == 1.0? 150 : 250),
You should also remove this code from the container:
width: value == 1.0 ? 80.0 : 60.0,
height: 30.0,
I have some code that creates 7 Raw Material Buttons in the shape of a circle. However I cannot seem to change the size of the circle, or position them closer together.
Page.dart
Row(
children: <Widget>[
new ThemeButton(Colors.red, () => print("red")),
new ThemeButton(Colors.orange, () => print("orange")),
new ThemeButton(Colors.yellow, () => print("yellow")),
new ThemeButton(Colors.green, () => print("green")),
new ThemeButton(Colors.blue, () => print("blue")),
new ThemeButton(Colors.indigo, () => print("pink")),
new ThemeButton(Colors.purple, () => print("purple")),
],
),
ThemeButton.dart
#override
Widget build(BuildContext context) {
return RawMaterialButton (
shape: CircleBorder(),
fillColor: _themeColour,
elevation: 0.0,
highlightElevation: 0.0,
onPressed: () => _onPressed(),
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
);
}
Display:
So the three issue I am facing are all around the size and positioning on the element.
The Circles are too small for my liking.
The space around the circles are too wide.
I can click outside the circle and it will still register the click.
I have looked at the arguments for the Raw Material Button and cannot see what I can change. Adding a padding widget and setting it to 0 doesn't help.
Changing the padding property, unfortunately, did not work for me. However, changing the constraints parameter like in this example turned out to be quite effective:
RawMaterialButton(
constraints: BoxConstraints.tight(Size(36, 36)),
onPressed: null,
child: Icon(Icons.trending_up, size: 18),
shape: new CircleBorder(),
elevation: 0.0,
fillColor: Color.fromARGB(255, 240, 240, 240),
),
Hope it helps!
According to the docs for RawMaterialButton, there should be a padding property that you can set in the constructor, which is typical for this type of component. Try updating the padding value in the constructor of the button instead of adding a new Widget. To be clear, trying setting padding to EdgeInsets.all(0.0).
For further sizing, you can start to look at the Row class properties, specifically MainAxisSize, or wrapping them in variations of the Flexible Widget family.
Let's say I want to position a widget inside a Stack but with a percent of the Stack position instead of a fixed size. How to do that in flutter ?
I'd expect that the Positionned.fromRelativeRect constructor would be the thing, using floats between 0 and 1. But seems like no.
Align allows to position the widget in percent. But heightFactor and widthFactor changes the Align size instead of the child size. Which is not what I want.
You can combine a Positioned.fill and LayoutBuilder to achieve such result.
new Stack(
children: <Widget>[
new Positioned.fill(
child: new LayoutBuilder(
builder: (context, constraints) {
return new Padding(
padding: new EdgeInsets.only(top: constraints.biggest.height * .59, bottom: constraints.biggest.height * .31),
child: new Text("toto", textAlign: TextAlign.center,),
);
},
),
)
],
),
one thing that i figured out not long ago is that you can position a widget on the screen using a container its alignment parameter with the help of the Alignment.lerp(x,y,z) function
//the widget will be placed in the center of the container
alignment: Alignment.lerp(Alignment.topCenter, Alignment.bottomCenter, 0),
//the widget will be placed in the bottom of the container
alignment: Alignment.lerp(Alignment.topCenter, Alignment.bottomCenter, 1),
//the widget will be placed in the bottom quarter of the container
alignment: Alignment.lerp(Alignment.topCenter, Alignment.bottomCenter, 0.5),
//the widget will be placed in the top quarter of the container
alignment: Alignment.lerp(Alignment.topCenter, Alignment.bottomCenter, -0.5),
use FractionalOffset & FractionallySizedBox it's very simple in contrast
around no unnecessary code like Positioned.fill
no no extra calculations like Alignment
...
Container(
color: Colors.blue[200],
alignment: FractionalOffset(0.7, 0.6),
child: FractionallySizedBox(
widthFactor: 0.1,
heightFactor: 1/3,
child: Container(color: Colors.red[900])
),
),
...
If you want to use LayoutBuilder then do without Positioned.fill, like this:
you need one LayoutBuilder, no need to turn around every elements and use Transform.translate instead of Padding.
new LayoutBuilder(
builder: (context, constraints) {
return Stack(
children: <Widget>[
Transform.translate(
offset: Offset(
constraints.biggest.width * left,
constraints.biggest.height * top),
child: new Text("toto", textAlign: TextAlign.center,),
),
...
],
);
}
)
The Flutter docs show an example of rotating a "div" by 15 degrees, both for HTML/CSS and Flutter code:
The Flutter code is:
var container = new Container( // gray box
child: new Center(
child: new Transform(
child: new Text(
"Lorem ipsum",
),
alignment: FractionalOffset.center,
transform: new Matrix4.identity()
..rotateZ(15 * 3.1415927 / 180),
),
),
);
And the relevant parts are new Transform and alignment: FractionalOffset.center and transform: new Matrix4.identity()..rotateZ(15 * 3.1415927 / 180)
I'm curious, is there a simpler way to rotate a Container in Flutter? Is there a short-hand for the case of "15 degrees" ?
Thanks!
In mobile apps, I think it's kind of rare to have things start out rotated 15 degrees and just stay there forever. So that may be why Flutter's support for rotation is better if you're planning to adjust the rotation over time.
It feels like overkill, but a RotationTransition with an AlwaysStoppedAnimation would accomplish exactly what you want.
new RotationTransition(
turns: new AlwaysStoppedAnimation(15 / 360),
child: new Text("Lorem ipsum"),
)
If you want to rotate something 90, 180, or 270 degrees, you can use a RotatedBox.
new RotatedBox(
quarterTurns: 1,
child: new Text("Lorem ipsum")
)
You can use Transform.rotate to rotate your widget. I used Text and rotated it with 45˚ (π/4)
Example:
import 'dart:math' as math;
Transform.rotate(
angle: -math.pi / 4,
child: Text('Text'),
)
If you are working with a canvas (as in a CustomPaint widget), you can rotate 15 degrees like this:
import 'dart:math' as math;
class MyPainter extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
canvas.save();
// rotate the canvas
final degrees = 15;
final radians = degrees * math.pi / 180;
canvas.rotate(radians);
// draw the text
final textStyle = TextStyle(color: Colors.black, fontSize: 30);
final textSpan = TextSpan(text: 'Hello, world.', style: textStyle);
TextPainter(text: textSpan, textDirection: TextDirection.ltr)
..layout(minWidth: 0, maxWidth: size.width)
..paint(canvas, Offset(0, 0));
canvas.restore();
}
#override
bool shouldRepaint(CustomPainter old) {
return false;
}
}
However, if you are doing something simple then I would use a RotatedBox or Transform.rotate as suggested by the other answers.
There is Two Main Flutter Widget available for this functionality, RotationTransition and Transform.rotate
another supported option is RotatedBox but this rotate widget only
supports quarter turns, which means they support vertical and only horizontal orientation.
and if you rotate already created widgets like Container so for the container by transformAlignmentyou can rotate widget.
RotationTransition: which animates the rotation of a widget, mainly we prefer when we need rotation with animation transition.https://api.flutter.dev/flutter/widgets/RotationTransition-class.html
Transform.rotate: which applies a rotation paint effect, they Create a widget that transforms its child using a rotation around the center.
RotationTransition Widget example:-
RotationTransition(
turns: AlwaysStoppedAnimation(15 / 360),
child: Text("flutter is awesome")
)
Transform.rotate Widget example :-
Transform.rotate(
angle: 15 * math.pi / 180,
child: Text("flutter is awesome")
)
Container(
decoration: BoxDecoration(borderRadius: BorderRadius.circular(50), color: Color(0xffF6F8FF),),
width: MediaQuery.of(context).size.width*0.6,
height: MediaQuery.of(context).size.height*0.4,
alignment:
new Alignment(0, 0),
transform:
new Matrix4.translationValues(MediaQuery.of(context).size.width * 0.55, -250.0, 0.0)
..rotateZ(28 * 3.1415927 / 180),
),