Open mohammadlatifalikhah opened 2 months ago
`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( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: ""), ); } }
class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title});
final String title;
@override
State
class _MyHomePageState extends State
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:
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(); });
} }