Stack List Of Widgets Timed Flutter

[Solved] Stack List Of Widgets Timed Flutter | Dart - Code Explorer | yomemimo.com
Question : Stack list of widgets timed flutter

Answered by : alert-angelfish-207vdiydsxys

import 'package:flutter/material.dart';
import 'dart:async';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); }
}
class MyHomePage extends StatefulWidget { final String title; const MyHomePage({ Key? key, required this.title, }) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> { late Timer _timer; List<Widget> history = []; int _counter = 0; void _updateHistory(Timer timer) { setState(() { _counter++; history.add(ListTile(title: Text(_counter.toString()))); }); } @override void initState() { super.initState(); _timer = Timer.periodic(const Duration(seconds: 1), _updateHistory); } @override void dispose() { super.dispose(); _timer.cancel(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: SingleChildScrollView( child: Column( children: history, ), ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { _counter = 0; history.clear(); }); }, tooltip: 'Clear all', child: const Icon(Icons.clear_all), ), ); }
}

Source : https://stackoverflow.com/questions/71773396/flutter-how-to-display-timer-updating-widget-list | Last Update : Thu, 26 May 22

Answers related to stack list of widgets timed flutter

Code Explorer Popular Question For Dart