How to play Gif file on png file? - flutter

Stack([
Image.asset(
"assets/Icon/Checkbox.png",
color: uncheckedColor,
height: 22,
width: 22,
),
Image.asset(
"assets/Icon/fullyComplete1.gif",
color: uncheckedColor,
scale: 2.5,
opacity: const AlwaysStoppedAnimation<double>(1.0),
height: 22,
width: 22,
gaplessPlayback: true,
)
])
I want play GIF file for 1 or 2 seconds then I have to show png file.
How can I achieve it?

You can, this solution is simple :
Add new variable in top class var show = false;
after that's add this function :
#override
void initState() {
Future.delayed(const Duration(seconds: 2), () {
setState(() => show = true);
});
super.initState();
}
Now add this your code
Stack([
show ? Image.asset(
"assets/Icon/Checkbox.png",
color: uncheckedColor,
height: 22,
width: 22,
) :
Image.asset(
"assets/Icon/fullyComplete1.gif",
color: uncheckedColor,
scale: 2.5,
opacity: const AlwaysStoppedAnimation<double>(1.0),
height: 22,
width: 22,
gaplessPlayback: true,
)
])

Related

How to make rating bar non clickable in flutter

How to make default flutter ratingbar non clickable ?
I have to disable rating option once user give feedback. How do I do it.
RatingBar(
itemSize: 35,
initialRating: 0,
glowColor: Colors.transparent,
direction: Axis.horizontal,
allowHalfRating: false,
tapOnlyMode: false,
itemCount: 5,
itemPadding: const EdgeInsets.symmetric(horizontal: 0.0),
ratingWidget: RatingWidget(
full: Image.asset(img_star_rating_fill, width: 25.w, height: 25.h),
// full: const Icon(Icons.star, color:yellow_FFC800),
half: Image.asset(img_star_rating_fill, width: 25.w, height: 25.h),
// half: const Icon(Icons.star_half, color:yellow_FFC800,),
empty:
Image.asset(img_star_rating_empty, width: 25.w, height: 25.h),
),
// empty: const Icon(Icons.star_outline, color:gray_868590,)),
onRatingUpdate: (value) {
setState(() {
_ratingValue = value;
printData(
'Rating to consultation booking ID', _ratingValue.toString());
controller
.callRateConsultationAPI(
widget.i,
controller.pastBookingList[widget.i].id.toString(),
value.toString())
.then((value) {
setState(() {
// ratingBar.setFocusable(false);
});
});
});
})
You can set ignoreGestures to true, like this:
RatingBar(
ignoreGestures: true, // <---- add this
itemSize: 35,
initialRating:0,
glowColor: Colors.transparent,
direction: Axis.horizontal,
allowHalfRating: false,
...
)
IgnorePointer(child:RatingWidget)

Pie chart issues in flutter

I'm using the fl_chart package to create an interactive Pie Chart for my application. Although the design came out fine, I'm facing the following issues with the functionality:
Tapping on a particular PieChartSectionData doesn't always select it and even tapping repeatedly doesn't help. It's always two out of the three that are tappable. Please note that the functionality works as it should for all the sections but there is no indication suggesting that the section tapped on was clicked. As defined in my code, every tap on a section should increase the radius and it's font size to make it stand out from the rest.
Every time a PieChartSectionData is clicked, it is supposed to navigate to a new page after a delay of 500 milliseconds. Although this works as expected, I cannot seem to come back to the previous page that has the Pie Chart on it using the phone's back button on the very first click. It is only after repeated clicks that it takes me back to the original page.
The chart seems to be clickable even beyond the PieChartSectionData. So like let's say if I tap an inch away from one of the sections, it tends to take me to that other page I need to navigate to. This shouldn't be the case.
Here is my code:
class ToDoListPieState extends State<ToDoListPie> {
int? index;
double? percent;
int? taskCount;
#override
Widget build(BuildContext context) {
final provider = Provider.of<TodaysTaskList>(context).getToDoList;
// TODO: implement build
return Stack(
children: [
PieChart(PieChartData(
borderData: FlBorderData(show: false),
pieTouchData: PieTouchData(
touchCallback: (FlTouchEvent event, pieTouchResponse) {
setState(() {
if (pieTouchResponse == null ||
pieTouchResponse.touchedSection == null) {
index = -1;
}
index = pieTouchResponse!.touchedSection!.touchedSectionIndex;
});
Future.delayed(const Duration(milliseconds: 500), () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => TaskList())); //This here is the event where clicking on a section should take us to the next page
});
print('Index: $index'); //This prints even if we click away from a section
},
),
sectionsSpace: 5,
centerSpaceRadius: 80,
sections: [
PieChartSectionData(
color: Colors.blue,
title: provider['upcoming'].length.toString(),
value: double.parse(provider['upcoming'].length.toString()),
radius: index == 0 ? 40 : 30,
titleStyle: TextStyle(fontSize: index == 0 ? 25 : 16)),
PieChartSectionData(
color: Colors.amber,
title: provider['today'].length.toString(),
value: double.parse(provider['today'].length.toString()),
radius: index == -1 ? 40 : 30,
titleStyle: TextStyle(fontSize: index == -1 ? 25 : 16)),
PieChartSectionData(
color: Colors.red,
title: provider['previous'].length.toString(),
value: double.parse(provider['previous'].length.toString()),
radius: index == 1 ? 40 : 30,
titleStyle: TextStyle(fontSize: index == 1 ? 25 : 16))
])),
Positioned(
left: 0,
top: SizeVariables.getHeight(context) * 0.18,
right: 0,
bottom: 0,
child: Column(
children: [
FittedBox(
fit: BoxFit.contain,
child: Text(
'${provider['upcoming'].length + provider['today'].length + provider['previous'].length}',
style: Theme.of(context)
.textTheme
.bodyText1!
.copyWith(fontSize: 25),
),
),
Text(
'Tasks',
style: Theme.of(context)
.textTheme
.bodyText1!
.copyWith(fontSize: 18),
)
],
),
)
],
);
}
}
Any help will be appreciated!

Flutter reduce padding of text in SleekCircularSlider

flutter reduces padding SleekCircularSlider and text. It's sowing too much space between bar and text.
my code
SleekCircularSlider(
min: 0,
max: 120.0,
initialValue: 60,
appearance: CircularSliderAppearance(
startAngle: 110,
angleRange: 70,
animationEnabled: true,
infoProperties: InfoProperties(
bottomLabelText: 'kg',
bottomLabelStyle: TextStyle(
fontSize: 20,
),
mainLabelStyle: TextStyle(
fontSize: 25,
fontFamily: 'RalewaySemiBold',
),
modifier: (double value) {
final roundedValue = value.ceil().toInt().toString();
return '$roundedValue ';
},
),
customColors: CustomSliderColors(
hideShadow: true,
trackColor: Color(0xffCFE7FB),
dotColor: Color(0XFFFAFAFA),
progressBarColor: kPrimaryColor,
),
customWidths: CustomSliderWidths(
trackWidth: 4,
progressBarWidth: 12,
handlerSize: 3,
)
),
onChangeEnd: (double weight){
return weight;
},
),
Look like this
I need to reduce the gap between bar and text.
You can use the size parameter on the CircularSliderAppearance to control how much width and height is allotted to your SleekCircularSlider widget.
For example, I added,
appearance: CircularSliderAppearance(
size: 100, // Added this
startAngle: 110,
and the output is this,
Play around and check what size suits you best. :)

Wait the data and the use it in the gui FLUTTER

I have a slider that uses a value to render himself, it start rendering after I hit a button but the first time I render it, it gives me an error and then starts working properly.
This is the error:
The getter 'inSeconds' was called on null.
Receiver: null
Tried calling: inSeconds
This is the widget that uses the data:
child: Consumer<MyAudio>(
builder: (context, audioPlayer, child) =>
SleekCircularSlider(
appearance: CircularSliderAppearance(
customWidths: CustomSliderWidths(
progressBarWidth: 2.0,
trackWidth: 1.0,
handlerSize: 1.0,
shadowWidth: 1.0,
),
infoProperties: InfoProperties(
modifier: (value) => '',
),
customColors: CustomSliderColors(
trackColor: Colors.grey,
progressBarColor: Colors.black,
),
size: 4.0,
angleRange: 360,
startAngle: -90.0,
),
min: 0.0,
max: audioPlayer.songLength.inSeconds.toDouble(),
initialValue:
audioPlayer.position.inSeconds.toDouble(),
),
),
),
And this is the function that gives me the values songLength and position:
class MyAudio extends ChangeNotifier {
Duration songLength;
Duration position;
AudioPlayer _player = AudioPlayer();
AudioCache cache;
MyAudio() {
initAudio();
}
initAudio() {
cache = AudioCache(fixedPlayer: _player);
_player.onDurationChanged.listen((Duration d) {
songLength = d;
notifyListeners();
});
_player.onAudioPositionChanged.listen((Duration p) {
position = p;
notifyListeners();
});
I think I should use an async function, what do you think?
If you need more code here's my github repo with all the files: https://github.com/astroxd/sputofy_mobile/tree/main/sputofy_2
the slider is in /lib/miniPlayer and the values are in /lib/model/audioPlayer
The problem is that when the widget is built for first time, the audioPlayer.songLength and audioPlayer.position are null despite audioPlayer is non-null.
In this fragment of code you define a pair of listeners, but the callbacks are called after the first build.
_player.onDurationChanged.listen((Duration d) {
songLength = d;
notifyListeners();
});
_player.onAudioPositionChanged.listen((Duration p) {
position = p;
notifyListeners();
});
Then, a solution can be the following:
child: Consumer<MyAudio>(
builder: (context, audioPlayer, child) => SleekCircularSlider(
appearance: CircularSliderAppearance(
customWidths: CustomSliderWidths(
progressBarWidth: 2.0,
trackWidth: 1.0,
handlerSize: 1.0,
shadowWidth: 1.0,
),
infoProperties: InfoProperties(
modifier: (value) => '',
),
customColors: CustomSliderColors(
trackColor: Colors.grey,
progressBarColor: Colors.black,
),
size: 4.0,
angleRange: 360,
startAngle: -90.0,
),
min: 0.0,
max: audioPlayer.songLength?.inSeconds?.toDouble() ?? 0.0,
initialValue: audioPlayer.position?.inSeconds?.toDouble() ?? 0.0,
),
)
Or maybe use a loader instead.

want to get an animated container small again to initial size with a click. It expands perfectly but I can't close it again

want to get an animated container small again to initial size with a click. It expands perfectly but I can't close it again.............................................................................................................................
child: AnimatedContainer(
duration: Duration(milliseconds: 200),
width: isTextOpen ? 200 : 95,
height: 50,
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(3)),
border: isTextOpen
? Border.all(
color: Colors.deepOrangeAccent,
width: 1.0,
)
: null,
),
child: isTextOpen
? TextField()
: GestureDetector(
onTap: () {
setState(() {
isTextOpen = true;
kapaac = 1;
});
},
child: Text(
"User_007",
style: TextStyle(
color: Colors.deepOrangeAccent,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
),
),
You are not setting it back to false.
setState(() => isTextOpen = !isTextOpen);
Once the user clicks the textbox if you want to get the textBox size to the initial size then you need to define a double variable with the expanded size then once the user clicks the text box for entering the text you need to reset the variable
double animatedContainerSize = 200;
After that set your AnimatedContainer widget width with the variable
width: isTextOpen ? animatedContainerSize : 95,
Then in your text box onTap function change the size to initial size with setState
isTextOpen
? TextField(
onTap: () {
setState(() {
animatedContainerSize = 95;
});
},
)