We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import 'dart:async';
import 'package:flutter/material.dart';
void main() { runApp(const MyApp()); }
class MyApp extends StatelessWidget { const MyApp({super.key});
// This widget is the root of your application. @OverRide Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } }
class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title});
final String title;
@OverRide State createState() => _MyHomePageState(); }
class _MyHomePageState extends State { bool isActive = false; int second = 0; Timer? timer;
void secondconter() { if (isActive) { setState(() { second += 1; }); } }
@OverRide Widget build(BuildContext context) { timer = Timer.periodic( Duration(seconds: 1), (timer) { secondconter(); });
int sec = second % 60; int min = ((second % 3600) / 60).toInt(); int hour = ( second / 3600).toInt(); return Scaffold( appBar: AppBar( backgroundColor: Colors.blue, title: Text( "Timer", style: TextStyle(color: Colors.black, fontSize: 40), )), body: Container( color: Colors.black, child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "$hour", style: TextStyle(color: Colors.white, fontSize: 50), ), Text( ":", style: TextStyle(color: Colors.white, fontSize: 50), ), Text( "$min", style: TextStyle(color: Colors.white, fontSize: 50), ), Text( ":", style: TextStyle(color: Colors.white, fontSize: 50), ), Text( "$sec", style: TextStyle(color: Colors.white, fontSize: 50), ) ], ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: () { setState(() { isActive=true; }); }, child: Text('Start'), ), SizedBox( width: 30, ), ElevatedButton( onPressed: () { setState(() { isActive=false; second=0; }); }, child: Text('Stop'), ), ], ) ], )), );
} }
The text was updated successfully, but these errors were encountered:
`import 'dart:async';
// This widget is the root of your application. @OverRide Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: ""), ); } }
class _MyHomePageState extends State { Timer? _timer; int _elapsedTime = 0; int _min = 0;
void startTimer() { _timer = Timer.periodic(Duration(seconds: 1), (timer) { setState(() { _elapsedTime++; if (_elapsedTime == 60) { _min++; _elapsedTime = 0; } }); }); }
void stopTimer() { _timer?.cancel(); }
@OverRide void dispose() { _timer?.cancel(); super.dispose(); }
@OverRide Widget build(BuildContext context) { return Scaffold( body: Container( color: Colors.deepPurple, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "$_min : $_elapsedTime ", style: TextStyle(fontSize: 48), ), SizedBox(height: 20), ElevatedButton( onPressed: stopTimer, child: Text('Stop'), ), ElevatedButton( onPressed: startTimer, child: Text("Start"), ), ], ), ), ), ); } } `
Sorry, something went wrong.
No branches or pull requests
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@OverRide
State createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
bool isActive = false;
int second = 0;
Timer? timer;
void secondconter() {
if (isActive) {
setState(() {
second += 1;
});
}
}
@OverRide
Widget build(BuildContext context) {
timer = Timer.periodic(
Duration(seconds: 1),
(timer) {
secondconter();
});
}
}
The text was updated successfully, but these errors were encountered: