Circular progress bar around avatar in Flutter - flutter

I'm trying to figure out how to create a broken-dash progress bar around a profile image in Flutter, but am unsure how to proceed.
My original plan revolved around using borders, but I don't seem to be able to choose the length of a border. It always wraps around the entire widget, which is not what I want.
An example of what I'm looking for would be https://dribbble.com/shots/13974030-Longwalks-iOS-App-featured-by-Oprah-Winfrey
Ideally, I'd want the bar to be broken up into 5 or 10 "chunks" that each represent some percentage for at-a-glance visualization.
Which widgets should I be using for this?

You can try using sleek_circular_slider.
You can use it as a slider or a progress bar. Here's an example of how it would be used.
For it to be used as a progress bar just remove the onChange or onChangeEnd, this will remove the user's ability to interact with it.
final slider = SleekCircularSlider(
min: 0,
max: 1000,
initialValue: 426,
onChange: (double value) {
// callback providing a value while its being changed (with a pan gesture)
},
onChangeStart: (double startValue) {
// callback providing a starting value (when a pan gesture starts)
},
onChangeEnd: (double endValue) {
// ucallback providing an ending value (when a pan gesture ends)
},
innerWidget: (double value) {
// use your custom widget inside the slider (gets a slider value from the callback)
},
);
I'm not sure about dividing it into 'chunks' but it should be possible.

dashed_circular_progress_bar: ^0.0.4 pluggin used
SizedBox(
height: 20,
width: 20,
child: DashedCircularProgressBar.aspectRatio(
aspectRatio: 2, // width รท height
progress: 25,
startAngle: 360,
sweepAngle: 360,
circleCenterAlignment: Alignment.bottomCenter,
foregroundColor: Colors.blue,
backgroundColor: const Color(0xffeeeeee),
foregroundStrokeWidth: 3,
backgroundStrokeWidth: 2,
backgroundGapSize: 2,
backgroundDashSize: 1,
//seekColor: Colors.yellow,
//seekSize: 22,
animation: true,
child: SizedBox(
child: Center(
child: Padding(
padding: const EdgeInsets.fromLTRB(0,8,12,3),
child: Icon(
Icons.play_arrow,
color: Colors.blue,
size: 20
),
),
),
),
),
)

Related

How to change widget brightness in Flutter?

In CSS I can use filter to change brightness. It's easy to make button hover effect.
filter: brightness(1.1);
filter: brightness(0.9);
Is there any way to change widget brightness in Flutter?
If your main goal is giving a hover effect on a button, you can use the combination of animated container(for the effect) and inkwell(onHover method to notify when hovering happens)
AnimatedContainer(
height: 70,
duration: Duration(milliseconds: 200),
padding: EdgeInsets.only(
top: (isHover) ? 25 : 30.0, bottom: !(isHover) ? 25 : 30),
child: Container(
height: 30,
color: Colors.blue,
child: InkWell(
onTap: () {},
child: Text("Hover Button"),
onHover: (val) {
print("Val--->{}$val");
setState(() {
isHover = val;
});
},
),
We do this in flutter
Colors.red.withOpacity(1.1);

How can I set initial position for slidable_button

I'd like to use slidable_button found here to set a bar happy hour on or off in my app. It doesn't have an initial position so I need to use two buttons, one to set happy hour on and another to turn it off. Ideally I'd like to have it initialize in either the left position or the right position depending on the current state. Unfortunately the package is very new and the author is not contactable.
Is there a way I could modify this code to set an initial button position left or right?
Here is the code I have so far. I have two buttons in separate rows in a column but have only shown the code for one as they are similar.
Center(
child: SlidableButton(
width: MediaQuery.of(context).size.width / 3,
buttonWidth: 60.0,
color: Colors.green,
buttonColor: Colors.blue,
dismissible: true,
label: Center(child: Text(_user.turnOnString!)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(''),
Text('Start'),
],
),
),
onChanged: (position) {
if (position == SlidableButtonPosition.right) {_startHappyHour(context, _user);}
},
),
),
switch button would be more suitable for your situation, like lite_rolling_switch, you can set initial value(on/off):
LiteRollingSwitch(
//initial value
value: true,
textOn: 'disponible',
textOff: 'ocupado',
colorOn: Colors.greenAccent[700],
colorOff: Colors.redAccent[700],
iconOn: Icons.done,
iconOff: Icons.remove_circle_outline,
textSize: 16.0,
onChanged: (bool state) {
//Use it to manage the different states
print('Current State of SWITCH IS: $state');
},
),

Flutter adding icon right after a long text

I want to add a tapable icon right after a long text. I need to use Text widget since I'm using textDirection and maxLines params.
Any ideas?
The problem:
What I need to get:
as Karen said it we need to use RichText.
Text.rich(
TextSpan(
text:
"I want to add a tapable icon right after a long text. I need to use Text widget since I'm using textDirection and maxLines params.",
children: [
WidgetSpan(
child: Icon(
Icons.error_outline,
color: Colors.red,
),
),
]),
),
the one way is to get char code of an icon, take a look at this answer for more details.
https://stackoverflow.com/a/63479589/10127437
Use a stack, let me show you...
Container(//Stack Widget needs space to work so be sure to add a container that gives it
width: double.infinity, //this makes the container match with the screen width
height: 200,
color: Colors.red,
child: Stack(
children: [
Positioned(//This widget gives position to your button
top: 100,//This will create a space on top
left: 0,//This will create a space on left
child: Container(//Your Container and text widget here
margin: EdgeInsets.only(left: 100),
height: 100,
width: 200,
color: Colors.blue,
child: Text(
"This is my text, my text takes more than one line, I want to present my Icon at the end of this text"
),
)
),
Positioned(
top: 140,
left: 150,
child: IconButton(//Put here your icon widget
iconSize: 30,
icon: Icon(CupertinoIcons.arrow_left_circle_fill),
color: Colors.blue,
)
),
],
),
)

Select number of items in list using gesture in flutter

I am new to flutter and have to implement a functionality to select correct words from list of alphabets.First of all here is the image which i have to make.
The alphabets and the correct words will come from the server side.What is was thinking is that i will place all the Alphabets in grid view/list view and when user will select words by using gesture on the alphabets . I know that what i am thinking may be wrong.If thats the case then please tell me the correct way to achieve what is given in the image ? Thanks in advance.
After doing some more research I think I can point you in the right direction and I wrote a small demonstration app that should help you so I found a good article explaining why I was having issues nesting widgets that both receive touch input. It is slightly complex but the gist of it is. If multiple touch inputs are detected they are handled in what is called the GestureArena and the child widget always wins. You can define your own GestureFactory and use RawGestureDetector to work around this issue. However, this might be more than you need for your application and in my opinion is the more complicated route. The route I went still involves just GestureDetector obviously you would need to expand on this as it only draws one oval at this time but that should be easy.
Offset position = Offset(0, 0);
bool isTapped = false;
double width = 50;
double height = 50;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Stack(
children: <Widget>[
Center(
child: Padding(
padding: const EdgeInsets.all(30.0),
child: GestureDetector(
child: GridView(
physics: NeverScrollableScrollPhysics(), //Very Important if
// you don't have this line you will have conflicting touch inputs and with
// gridview being the child will win
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
childAspectRatio: 2,
),
children: <Widget>[
...letters
.map(
(letter) => Text(
letter,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.amber,
fontSize: 18,
),
),
)
.toList(),
],
),
onTapDown: (TapDownDetails details) {
//User Taps Screen
print('Global Position: ${details.globalPosition}');
setState(() {
position = Offset(
details.globalPosition.dx - 25,
details.globalPosition.dy - 25,
);
isTapped = true;
});
print(position);
},
onVerticalDragUpdate: (DragUpdateDetails details) {
print('${details.delta.dy}');
setState(() {
height += details.delta.dy;
});
},
onHorizontalDragUpdate: (DragUpdateDetails details) {
print('${details.delta.dx}');
setState(() {
width += details.delta.dx;
});
},
onTapCancel: () {
//User has released finger from screen
//Validate Word??
},
),
),
),
Positioned(
top: position.dy,
left: position.dx,
child: Container(
height: height,
width: width,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
side: BorderSide(
color: isTapped ? Colors.blue : Colors.transparent,
width: 3.0),
),
),
),
),
],
),
);
}
Flutter Deep Dive: Gestures found this very helpful key to figuring this all out.

Blog or tutorial for layering different widgets and keeping some layers transparent

What i am trying to achieve is i have a alphabet 'A' on the screen. Inside the text body i want to show a container whose height is varying. So in the background screen lets say the color is green. The text 'A' on the screen is transparent. Inside 'A' text is filled with color yellow. But the color lowers its height level gradually. And a new color is revealed for the reduced height space, lets say pink.
If your saying that your using text, changing height in order to change the color. Heres my solution in three step.
1.Use stack
2.Use Animated Container to lower the height
3.Use Timer with a duration of 1sec.
#override
void initState() {
super.initState();
Timer.periodic(Duration(seconds: 1), (Timer t) => changeHight());
}
changeHight(){
setState(() {
textHeight = 200;
});
}
Stack(
children: <Widget>[
Container(
color: Colors.green,
width: 200.0,
height: 200.0,
child: Align(
alignment: Alignment.topCenter,
child: Text("A",style: TextStyle(fontSize: 200,color: Colors.yellow),))
),
AnimatedContainer(
alignment: Alignment.topCenter,
duration: Duration(seconds: 2),
height: textHeight,
width: 200,
child: Text("A",style: TextStyle(fontSize: 200,color: Colors.pink),)
)
],
),