Circular Count Down Timer Flutter - flutter

How can I get the "00" off my count down when the time is up?
Widget _buildTimer() {
return CircularCountDownTimer(
fillColor: Colors.red,
color: Colors.white,
backgroundColor: null,
duration: _data[_currentIndex].duration,
controller: _controller,
width: MediaQuery.of(context).size.width / 4,
height: MediaQuery.of(context).size.height / 4,
strokeWidth: 10.0,
strokeCap: StrokeCap.round,
textStyle: TextStyle(
fontSize: 33.0, color: Colors.black, fontWeight: FontWeight.bold),
textFormat: CountdownTextFormat.SS,
isReverse: true,
isReverseAnimation: true,
isTimerTextShown: true,
autoStart: true,
);
}
When the time runs out it looks like this
enter image description here
Can anyone in help?

I assume you are using this https://pub.dev/packages/circular_countdown_timer
In that case, you need to have a variable controlling the state of the text visibility. Then you can change this in the onComplete callback.
bool isTimerShown = true;
#override
Widget build(BuildContext context) {
return Scaffold(
body: CircularCountDownTimer(
fillColor: Colors.red,
backgroundColor: null,
duration: 3,
controller: CountDownController(),
width: MediaQuery
.of(context)
.size
.width / 4,
height: MediaQuery
.of(context)
.size
.height / 4,
strokeWidth: 10.0,
strokeCap: StrokeCap.round,
textStyle: TextStyle(
fontSize: 33.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
textFormat: CountdownTextFormat.SS,
isReverse: true,
isReverseAnimation: true,
isTimerTextShown: isTimerShown,
autoStart: true,
ringColor: Colors.white,
onComplete: () =>
setState(() {
isTimerShown = false;
}),
),
);
}

Related

DropdownMenuItems are not rebuilding flutter using DropdownButton2

My dropdown list has a multi-select feature. I have shown the list and selected Items are saved in an array called selectedClassList. Basically, it's a normal checkbox procedure.
But in the scenario of clicking a value called "any", I need to unselect all other items and need to mark "Any" as selected. The same is for other items, when a user clicks any of the other items, then item "any" should get unselected.
My code is like
DropdownButtonFormField2<dynamic>(
itemHeight: 40,
dropdownOverButton: false,
buttonWidth: double.infinity,
selectedItemHighlightColor: Colors.grey.shade300,
isExpanded: true,
value: widget.value,
dropdownElevation: 0,
itemPadding: const EdgeInsets.only(left: 15),
buttonDecoration: BoxDecoration(
border: Border.all(color: Colors.black87, width: 1),
borderRadius: BorderRadius.circular(5),
),
decoration: const InputDecoration.collapsed(
hintText: '',
border: InputBorder.none,
),
isDense: true,
offset: const Offset(0, -2),
iconSize: 20,
buttonHeight: 50,
buttonPadding: const EdgeInsets.only(left: 15, right: 10),
focusColor: const Color(0xffFFFFFF),
hint: const Text('Select One',
style: TextStyle(
fontSize: 14,
fontFamily: 'Poppins, Regular',
color: Color(0xffAAAAAA))),
style: const TextStyle(
fontSize: 14,
fontFamily: 'Poppins, Regular',
overflow: TextOverflow.ellipsis,
color: Color(0xff121212)),
iconOnClick: AnimatedRotation(
turns: 0.5,
duration: const Duration(milliseconds: 300),
child: Icon(Icons.arrow_down),
),
icon: AnimatedRotation(
turns: 1,
duration: const Duration(milliseconds: 300),
child: Icon(Icons.arrow_up),
),
dropdownDecoration: BoxDecoration(
border: Border.all(
color: Colors.black45,
width: 1,
),
borderRadius: const BorderRadius.all(Radius.circular(5)),
shape: BoxShape.rectangle),
dropdownMaxHeight: 200,
items: getClassDetails.data?.map((item) {
return DropdownMenuItem<dynamic>(
value: item,
enabled: false,
child: StatefulBuilder(
builder: (context, menuSetState) {
var _isSelected = selectedClass!
.where((element) =>
element.settingName == item.settingName)
.toList()
.isNotEmpty;
return InkWell(
onTap: () {
if (item.settingName == "Any") {
selectedClass!.clear();
}
if (_isSelected == true) {
selectedClass!.remove(item);
} else {
selectedClass!.add(item);
}
setState(() {});
menuSetState(() {});
},
child: Row(
children: [
_isSelected
? const Icon(Icons.check_box_outlined)
: const Icon(Icons.check_box_outline_blank),
const SizedBox(width: 16),
Text(
item.settingName.toString(),
style: const TextStyle(
fontSize: 14,
fontFamily: 'Poppins, Regular',
color: Color(0xff121212)),
),
],
),
);
},
),
);
}).toList(),
)
I am not good at explaining things. Kindly let me know if I made any mistake.

The named parameter 'textStyle' isn't defined

How to fix this error. Someone can help me?
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
AspectRatio(
aspectRatio: 1.70,
child: Container(
height: 250,
padding: EdgeInsets.all(20),
child: LineChart(
mainData(),
),
),
),
],
);
}
LineChartData mainData() {
return LineChartData(
gridData: FlGridData(
show: true,
drawVerticalLine: true,
getDrawingHorizontalLine: (value) {
return FlLine(
color: Color.fromRGBO(0, 0, 0, 0.3),
strokeWidth: 1,
);
},
getDrawingVerticalLine: (value) {
return FlLine(
color: Color.fromRGBO(0, 0, 0, 0.3),
strokeWidth: 1,
);
},
),
titlesData: FlTitlesData(
show: true,
bottomTitles: SideTitles(
showTitles: true,
reservedSize: 10,
rotateAngle: -90,
textStyle: const TextStyle(color: Color(0xff68737d),
fontWeight: FontWeight.bold, fontSize: 10),
getTitles: (value) { //ERROR textStyle
SideTitle's textStyle property changed to getTextStyles getter (it gives you the axis value, and you must return a TextStyle based on it), It helps you to have a different style for specific text, check it in 0.12.0. Therefore, try:
getTextStyles: (BuildContext context, double v) {
return TextStyle(color: Color(0xff68737d), fontWeight: FontWeight.bold, fontSize: 10);
},
After flutter update the textStyle is changed to getTextStyles. Try below code, hope its help to you. Refer SideTitles
SideTitles(
showTitles: true,
reservedSize: 10,
rotateAngle: -90,
getTextStyles: (BuildContext context, double v) {
return TextStyle(color: Color.red,
fontWeight: FontWeight.bold,
fontSize: 15,
);
},
),

Flutter circular_countdown_timer time restarts when pushing to screen

I'am using the circular_countdown_timer package from pub.dev everytime i leave the screen that has the countdown_timer and push back to the screen the timer restarts from 0, is there a way to save the timer state ?
And this is my code:
CircularCountDownTimer(
duration: 10,
initialDuration: 0,
controller: CountDownController(),
width: 55.0,
height: 85.0,
ringColor:
Color(0x30A6CA).withOpacity(0.1),
ringGradient: null,
fillColor: Color(0xFF30A6CA),
fillGradient: null,
backgroundColor: Colors.transparent,
backgroundGradient: null,
strokeWidth: 10.0,
strokeCap: StrokeCap.round,
textStyle: GoogleFonts.roboto(
fontSize: 14.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
textFormat: CountdownTextFormat.MM_SS,
isReverse: true,
isReverseAnimation: false,
isTimerTextShown: true,
autoStart: true,
onStart: () {},
onComplete: () {},
),

Displaying time selected from TimePicker to display Local Notification in Flutter App

I want to show Local Notification at the time that I have selected using TimePicker. I can call the function of scheduleAlaram() but I cannot send the time that i selected. Please help me out with how do I send this time to my function in order to display local notification.
This is my code:
import 'package:epicare/Medicines.dart';
import 'package:flutter/material.dart';
import 'package:flutter_switch/flutter_switch.dart';
class AddMedicine extends StatefulWidget {
#override
_AddMedicineState createState() => _AddMedicineState();
}
class _AddMedicineState extends State<AddMedicine> {
final timeController = TextEditingController();
Widget build(BuildContext context) {
String value = "";
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(),
body: SingleChildScrollView(
child: Column(
children: [
Container(
width: size.width,
padding: EdgeInsets.symmetric(horizontal: 34, vertical: 13),
child: Text(
'Reminder',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 14,
color: const Color(0xff000000),
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.left,
),
),
Container(
width: size.width * 0.85,
height: 52,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.0),
color: const Color(0xffffffff),
border: Border.all(width: 1.0, color: const Color(0xffdbe2ea)),
boxShadow: [
BoxShadow(
color: const Color(0x0a2c2738),
offset: Offset(0, 4),
blurRadius: 8,
),
],
),
child: TextField(
controller: timeController,
readOnly: true,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12,
color: const Color(0xff000000),
fontWeight: FontWeight.w500,
),
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: () async {
var time = await showTimePicker(
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.light().copyWith(
colorScheme: ColorScheme.dark(
primary: const Color(0xffE5E0A1),
onPrimary: Colors.black,
surface: Colors.white,
onSurface: Colors.black,
),
dialogBackgroundColor:Colors.white,
),
child: child,
);
},
context: context,
initialTime: TimeOfDay.now(),
);
print(time.format(context));
timeController.text = time.format(context);
scheduleAlarm();
},
icon: Icon(
Icons.add_alert,
color: const Color(0xffd4d411),
),
),
contentPadding:
const EdgeInsets.symmetric(vertical: 18, horizontal: 20),
border: InputBorder.none,
hintText: "Add time(s) to eat your medicine",
hintStyle: TextStyle(
fontFamily: 'Montserrat',
fontSize: 13,
color: const Color(0xffcbd0d6),
),
),
onChanged: (text) {
value = text;
print(value);
},
),
),
],
),
),
);
}
void scheduleAlarm() async {
//print("hello");
var time = Time(2, 37, 0);
var androidPlatformChannelSpecifics =
AndroidNotificationDetails('repeatDailyAtTime channel id',
'repeatDailyAtTime channel name', 'repeatDailyAtTime description');
var iOSPlatformChannelSpecifics =
IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showDailyAtTime(
0,
'show daily title',
'Daily notification shown at approximately ${(time.hour)}:${(time.minute)}}',
time,
platformChannelSpecifics);
}
}
This is the screen which I am currently working on and I am on Reminder section to display notification:
how do I send this time to my function in order to display local notification.
Update showAlarm() to accept an argument for the time like so:
void scheduleAlarm(Time time) {
...
}
Since showDailyAtTime() accepts a value of Time, you should call the updated function after converting the value from the textcontroller to a Time value,
Time.format(context) will return a String so it cannot be used,
However you can modify this line var time = Time(2, 37, 0); to create a time value from the inputvalue and convert it to time using Time() which can then be sent to the scheduleAlarm() function

How to change parameters of widget itself after onComplete function

I need to find solution on how to change parameters of widget after onComplete function.
child: CircularCountDownTimer(
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.height / 2,
duration: 3,
fillColor: Colors.amber,
ringColor: Colors.green,
controller: _controller,
backgroundColor: Colors.white54,
strokeWidth: 10.0,
strokeCap: StrokeCap.round,
isTimerTextShown: true,
isReverse: false,
onComplete: () {},
textStyle: TextStyle(fontSize: 50.0, color: Colors.black),
),
Define a variable for the property. For example the color you want to change.
MaterialColor fillcolor = Colors.amber;
Then change it inside onComplete method
child: CircularCountDownTimer(
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.height / 2,
duration: 3,
fillColor: fillcolor,
ringColor: Colors.green,
controller: _controller,
backgroundColor: Colors.white54,
strokeWidth: 10.0,
strokeCap: StrokeCap.round,
isTimerTextShown: true,
isReverse: false,
onComplete: () {
setState(() {
fillcolor = Colors.purple
});
},
textStyle: TextStyle(fontSize: 50.0, color: Colors.black),
),