How to implement a timer not on the root widget but on its own widget?Flutter Layout: How can I put a Row inside a Flex (or another Row) in Flutter? Also using Stack widgetFlutter : Can I add a Header Row to a ListViewHow to offset a scaffold widget in Flutter?How to implement cycle wheel scroll list widgetFlutter : Bad state: Stream has already been listened toHow to cancel a running Timer() when Widget disappearsshowDialog from root widgetHow I can put Widget above Widget using List<Widget> widget in Flutter?hello ,,,,,when I am clicking on card then show me this error how to fix this error

Is this resistor leaking? If so, is it a concern?

Rests in pickup measure (anacrusis)

What do different value notes on the same line mean?

Why is this Simple Puzzle impossible to solve?

Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?

Would the Geas spell work in a dead magic zone once you enter it?

What does it mean when you think without speaking?

Full horizontal justification in table

Plot twist where the antagonist wins

Why colon to denote that a value belongs to a type?

Placing bypass capacitors after VCC reaches the IC

What are these (utility?) boxes at the side of the house?

Tabulated absorption spectra of greenhouse gases?

1960s sci-fi novella with a character who is treated as invisible by being ignored

Is one obligated to listen to a Rav?

How many chess players are over 2500 Elo?

Why doesn't the Earth's acceleration towards the Moon accumulate to push the Earth off its orbit?

Is there a general effective method to solve Smullyan style Knights and Knaves problems? Is the truth table method the most appropriate one?

What is the largest (size) solid object ever dropped from an airplane to impact the ground in freefall?

Apparent Ring of Craters on the Moon

What's the Difference between Two Single-Quotes and One Double-Quote?

Is CD audio quality good enough for the final delivery of music?

Is there any use case for the bottom type as a function parameter type?

How to plot an unstable attractor?



How to implement a timer not on the root widget but on its own widget?


Flutter Layout: How can I put a Row inside a Flex (or another Row) in Flutter? Also using Stack widgetFlutter : Can I add a Header Row to a ListViewHow to offset a scaffold widget in Flutter?How to implement cycle wheel scroll list widgetFlutter : Bad state: Stream has already been listened toHow to cancel a running Timer() when Widget disappearsshowDialog from root widgetHow I can put Widget above Widget using List<Widget> widget in Flutter?hello ,,,,,when I am clicking on card then show me this error how to fix this error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am working on a meditation app. Here's the link to the github repo: https://github.com/dscognitif/Sati_App



I am trying to implement a timer on one of the app states specifically the timer state. I have found some inspiration from a flutter tutorial: (https://github.com/tensor-programming/flutter_timer_example) on how to implement the timer but they've implemented it on the root widget of the app and I would like for it to be on its own widget. How could I accomplish this?



Here's the code:




import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() => runApp(MaterialApp(
home: MyApp(),
theme: ThemeData(
canvasColor: Colors.blueGrey,
iconTheme: IconThemeData(
color: Colors.white,
),
accentColor: Colors.pinkAccent,
brightness: Brightness.dark,
),
));

class MyApp extends StatefulWidget
@override
MyAppState createState() => MyAppState();


class MyAppState extends State<MyApp> with TickerProviderStateMixin
AnimationController controller;

String get timerString
Duration duration = controller.duration * controller.value;
return '$duration.inMinutes:$(duration.inSeconds % 60).toString().padLeft(2, '0')';


@override
void initState()
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(seconds: 10),
);


@override
Widget build(BuildContext context)
ThemeData themeData = Theme.of(context);
return Scaffold(
body: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Align(
alignment: FractionalOffset.center,
child: AspectRatio(
aspectRatio: 1.0,
child: Stack(
children: <Widget>[
Positioned.fill(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return CustomPaint(
painter: TimerPainter(
animation: controller,
backgroundColor: Colors.white,
color: themeData.indicatorColor,
));
,
),
),
Align(
alignment: FractionalOffset.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Count Down",
style: themeData.textTheme.subhead,
),
AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Text(
timerString,
style: themeData.textTheme.display4,
);
),
],
),
),
],
),
),
),
),
Container(
margin: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Icon(controller.isAnimating
? Icons.pause
: Icons.play_arrow);
,
),
onPressed: ()
if (controller.isAnimating)
controller.stop();
else
controller.reverse(
from: controller.value == 0.0
? 1.0
: controller.value);

,
)
],
),
)
],
),
),
);



class TimerPainter extends CustomPainter
TimerPainter(
this.animation,
this.backgroundColor,
this.color,
) : super(repaint: animation);

final Animation<double> animation;
final Color backgroundColor, color;

@override
void paint(Canvas canvas, Size size)
Paint paint = Paint()
..color = backgroundColor
..strokeWidth = 5.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;

canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
paint.color = color;
double progress = (1.0 - animation.value) * 2 * math.pi;
canvas.drawArc(Offset.zero & size, math.pi * 1.5, -progress, false, paint);


@override
bool shouldRepaint(TimerPainter old)
return animation.value != old.animation.value











share|improve this question






















  • you want an animated CustomPainter or something else? what do you want to achieve actually?

    – pskink
    Mar 24 at 7:13












  • Yes I want to achieve an animated CustomPainter as a timer but not on the root widget as this code shows but on another widget.

    – Ronin Winter
    Mar 24 at 7:51






  • 1





    so add CustomPaint to that "another widget", what is the problem here?

    – pskink
    Mar 24 at 7:52












  • Alright, let me try that. Thanks!

    – Ronin Winter
    Mar 24 at 8:44

















0















I am working on a meditation app. Here's the link to the github repo: https://github.com/dscognitif/Sati_App



I am trying to implement a timer on one of the app states specifically the timer state. I have found some inspiration from a flutter tutorial: (https://github.com/tensor-programming/flutter_timer_example) on how to implement the timer but they've implemented it on the root widget of the app and I would like for it to be on its own widget. How could I accomplish this?



Here's the code:




import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() => runApp(MaterialApp(
home: MyApp(),
theme: ThemeData(
canvasColor: Colors.blueGrey,
iconTheme: IconThemeData(
color: Colors.white,
),
accentColor: Colors.pinkAccent,
brightness: Brightness.dark,
),
));

class MyApp extends StatefulWidget
@override
MyAppState createState() => MyAppState();


class MyAppState extends State<MyApp> with TickerProviderStateMixin
AnimationController controller;

String get timerString
Duration duration = controller.duration * controller.value;
return '$duration.inMinutes:$(duration.inSeconds % 60).toString().padLeft(2, '0')';


@override
void initState()
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(seconds: 10),
);


@override
Widget build(BuildContext context)
ThemeData themeData = Theme.of(context);
return Scaffold(
body: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Align(
alignment: FractionalOffset.center,
child: AspectRatio(
aspectRatio: 1.0,
child: Stack(
children: <Widget>[
Positioned.fill(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return CustomPaint(
painter: TimerPainter(
animation: controller,
backgroundColor: Colors.white,
color: themeData.indicatorColor,
));
,
),
),
Align(
alignment: FractionalOffset.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Count Down",
style: themeData.textTheme.subhead,
),
AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Text(
timerString,
style: themeData.textTheme.display4,
);
),
],
),
),
],
),
),
),
),
Container(
margin: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Icon(controller.isAnimating
? Icons.pause
: Icons.play_arrow);
,
),
onPressed: ()
if (controller.isAnimating)
controller.stop();
else
controller.reverse(
from: controller.value == 0.0
? 1.0
: controller.value);

,
)
],
),
)
],
),
),
);



class TimerPainter extends CustomPainter
TimerPainter(
this.animation,
this.backgroundColor,
this.color,
) : super(repaint: animation);

final Animation<double> animation;
final Color backgroundColor, color;

@override
void paint(Canvas canvas, Size size)
Paint paint = Paint()
..color = backgroundColor
..strokeWidth = 5.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;

canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
paint.color = color;
double progress = (1.0 - animation.value) * 2 * math.pi;
canvas.drawArc(Offset.zero & size, math.pi * 1.5, -progress, false, paint);


@override
bool shouldRepaint(TimerPainter old)
return animation.value != old.animation.value











share|improve this question






















  • you want an animated CustomPainter or something else? what do you want to achieve actually?

    – pskink
    Mar 24 at 7:13












  • Yes I want to achieve an animated CustomPainter as a timer but not on the root widget as this code shows but on another widget.

    – Ronin Winter
    Mar 24 at 7:51






  • 1





    so add CustomPaint to that "another widget", what is the problem here?

    – pskink
    Mar 24 at 7:52












  • Alright, let me try that. Thanks!

    – Ronin Winter
    Mar 24 at 8:44













0












0








0


0






I am working on a meditation app. Here's the link to the github repo: https://github.com/dscognitif/Sati_App



I am trying to implement a timer on one of the app states specifically the timer state. I have found some inspiration from a flutter tutorial: (https://github.com/tensor-programming/flutter_timer_example) on how to implement the timer but they've implemented it on the root widget of the app and I would like for it to be on its own widget. How could I accomplish this?



Here's the code:




import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() => runApp(MaterialApp(
home: MyApp(),
theme: ThemeData(
canvasColor: Colors.blueGrey,
iconTheme: IconThemeData(
color: Colors.white,
),
accentColor: Colors.pinkAccent,
brightness: Brightness.dark,
),
));

class MyApp extends StatefulWidget
@override
MyAppState createState() => MyAppState();


class MyAppState extends State<MyApp> with TickerProviderStateMixin
AnimationController controller;

String get timerString
Duration duration = controller.duration * controller.value;
return '$duration.inMinutes:$(duration.inSeconds % 60).toString().padLeft(2, '0')';


@override
void initState()
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(seconds: 10),
);


@override
Widget build(BuildContext context)
ThemeData themeData = Theme.of(context);
return Scaffold(
body: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Align(
alignment: FractionalOffset.center,
child: AspectRatio(
aspectRatio: 1.0,
child: Stack(
children: <Widget>[
Positioned.fill(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return CustomPaint(
painter: TimerPainter(
animation: controller,
backgroundColor: Colors.white,
color: themeData.indicatorColor,
));
,
),
),
Align(
alignment: FractionalOffset.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Count Down",
style: themeData.textTheme.subhead,
),
AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Text(
timerString,
style: themeData.textTheme.display4,
);
),
],
),
),
],
),
),
),
),
Container(
margin: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Icon(controller.isAnimating
? Icons.pause
: Icons.play_arrow);
,
),
onPressed: ()
if (controller.isAnimating)
controller.stop();
else
controller.reverse(
from: controller.value == 0.0
? 1.0
: controller.value);

,
)
],
),
)
],
),
),
);



class TimerPainter extends CustomPainter
TimerPainter(
this.animation,
this.backgroundColor,
this.color,
) : super(repaint: animation);

final Animation<double> animation;
final Color backgroundColor, color;

@override
void paint(Canvas canvas, Size size)
Paint paint = Paint()
..color = backgroundColor
..strokeWidth = 5.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;

canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
paint.color = color;
double progress = (1.0 - animation.value) * 2 * math.pi;
canvas.drawArc(Offset.zero & size, math.pi * 1.5, -progress, false, paint);


@override
bool shouldRepaint(TimerPainter old)
return animation.value != old.animation.value











share|improve this question














I am working on a meditation app. Here's the link to the github repo: https://github.com/dscognitif/Sati_App



I am trying to implement a timer on one of the app states specifically the timer state. I have found some inspiration from a flutter tutorial: (https://github.com/tensor-programming/flutter_timer_example) on how to implement the timer but they've implemented it on the root widget of the app and I would like for it to be on its own widget. How could I accomplish this?



Here's the code:




import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() => runApp(MaterialApp(
home: MyApp(),
theme: ThemeData(
canvasColor: Colors.blueGrey,
iconTheme: IconThemeData(
color: Colors.white,
),
accentColor: Colors.pinkAccent,
brightness: Brightness.dark,
),
));

class MyApp extends StatefulWidget
@override
MyAppState createState() => MyAppState();


class MyAppState extends State<MyApp> with TickerProviderStateMixin
AnimationController controller;

String get timerString
Duration duration = controller.duration * controller.value;
return '$duration.inMinutes:$(duration.inSeconds % 60).toString().padLeft(2, '0')';


@override
void initState()
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(seconds: 10),
);


@override
Widget build(BuildContext context)
ThemeData themeData = Theme.of(context);
return Scaffold(
body: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Align(
alignment: FractionalOffset.center,
child: AspectRatio(
aspectRatio: 1.0,
child: Stack(
children: <Widget>[
Positioned.fill(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return CustomPaint(
painter: TimerPainter(
animation: controller,
backgroundColor: Colors.white,
color: themeData.indicatorColor,
));
,
),
),
Align(
alignment: FractionalOffset.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Count Down",
style: themeData.textTheme.subhead,
),
AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Text(
timerString,
style: themeData.textTheme.display4,
);
),
],
),
),
],
),
),
),
),
Container(
margin: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
child: AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child)
return Icon(controller.isAnimating
? Icons.pause
: Icons.play_arrow);
,
),
onPressed: ()
if (controller.isAnimating)
controller.stop();
else
controller.reverse(
from: controller.value == 0.0
? 1.0
: controller.value);

,
)
],
),
)
],
),
),
);



class TimerPainter extends CustomPainter
TimerPainter(
this.animation,
this.backgroundColor,
this.color,
) : super(repaint: animation);

final Animation<double> animation;
final Color backgroundColor, color;

@override
void paint(Canvas canvas, Size size)
Paint paint = Paint()
..color = backgroundColor
..strokeWidth = 5.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;

canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
paint.color = color;
double progress = (1.0 - animation.value) * 2 * math.pi;
canvas.drawArc(Offset.zero & size, math.pi * 1.5, -progress, false, paint);


@override
bool shouldRepaint(TimerPainter old)
return animation.value != old.animation.value








flutter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 7:08









Ronin WinterRonin Winter

33




33












  • you want an animated CustomPainter or something else? what do you want to achieve actually?

    – pskink
    Mar 24 at 7:13












  • Yes I want to achieve an animated CustomPainter as a timer but not on the root widget as this code shows but on another widget.

    – Ronin Winter
    Mar 24 at 7:51






  • 1





    so add CustomPaint to that "another widget", what is the problem here?

    – pskink
    Mar 24 at 7:52












  • Alright, let me try that. Thanks!

    – Ronin Winter
    Mar 24 at 8:44

















  • you want an animated CustomPainter or something else? what do you want to achieve actually?

    – pskink
    Mar 24 at 7:13












  • Yes I want to achieve an animated CustomPainter as a timer but not on the root widget as this code shows but on another widget.

    – Ronin Winter
    Mar 24 at 7:51






  • 1





    so add CustomPaint to that "another widget", what is the problem here?

    – pskink
    Mar 24 at 7:52












  • Alright, let me try that. Thanks!

    – Ronin Winter
    Mar 24 at 8:44
















you want an animated CustomPainter or something else? what do you want to achieve actually?

– pskink
Mar 24 at 7:13






you want an animated CustomPainter or something else? what do you want to achieve actually?

– pskink
Mar 24 at 7:13














Yes I want to achieve an animated CustomPainter as a timer but not on the root widget as this code shows but on another widget.

– Ronin Winter
Mar 24 at 7:51





Yes I want to achieve an animated CustomPainter as a timer but not on the root widget as this code shows but on another widget.

– Ronin Winter
Mar 24 at 7:51




1




1





so add CustomPaint to that "another widget", what is the problem here?

– pskink
Mar 24 at 7:52






so add CustomPaint to that "another widget", what is the problem here?

– pskink
Mar 24 at 7:52














Alright, let me try that. Thanks!

– Ronin Winter
Mar 24 at 8:44





Alright, let me try that. Thanks!

– Ronin Winter
Mar 24 at 8:44












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321481%2fhow-to-implement-a-timer-not-on-the-root-widget-but-on-its-own-widget%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321481%2fhow-to-implement-a-timer-not-on-the-root-widget-but-on-its-own-widget%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript