### Flutter Stopwatch with Limited Time Logs Source: https://github.com/dhwani-19/fluttertask/blob/main/README.md Implements a Flutter Stopwatch that starts on button click. Once started, it logs the current time to a ListView every 20 seconds. The ListView has a maximum capacity of 15 logs, after which a 'Time Over' message is displayed. Any state management approach can be used. ```dart import 'package:flutter/material.dart'; import 'dart:async'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Stopwatch Logger', home: StopwatchScreen(), ); } } class StopwatchScreen extends StatefulWidget { @override _StopwatchScreenState createState() => _StopwatchScreenState(); } class _StopwatchScreenState extends State { bool _isRunning = false; Timer? _timer; final List _timeLogs = []; static const int MAX_LOGS = 15; void _startStopwatch() { if (!_isRunning) { setState(() { _isRunning = true; _timeLogs.clear(); // Clear logs on new start }); _timer = Timer.periodic(Duration(seconds: 20), (timer) { if (_timeLogs.length < MAX_LOGS) { setState(() { _timeLogs.add('Log at: ${DateTime.now().toIso8601String()}'); }); } else { _timer?.cancel(); setState(() { _isRunning = false; }); } }); } } @override void dispose() { _timer?.cancel(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Stopwatch Logger'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ ElevatedButton( onPressed: _startStopwatch, child: Text(_isRunning ? 'Running...' : 'Start Stopwatch'), style: ElevatedButton.styleFrom( primary: _isRunning ? Colors.grey : Theme.of(context).primaryColor, ), ), SizedBox(height: 20), Expanded( child: _timeLogs.isEmpty && !_isRunning ? Center(child: Text('Press Start to begin logging.')) : ListView.builder( itemCount: _timeLogs.length < MAX_LOGS ? _timeLogs.length : MAX_LOGS + 1, itemBuilder: (context, index) { if (index < _timeLogs.length) { return ListTile( title: Text(_timeLogs[index]), ); } else { return Center(child: Text('Time Over')); } }, ), ), ], ), ), ); } } ``` -------------------------------- ### Flutter TextField and Button Input Display Source: https://github.com/dhwani-19/fluttertask/blob/main/README.md Demonstrates a simple Flutter application with a TextField to capture user input and a Button to display that input using a Text widget. This covers basic UI interaction and state management. ```dart import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Input Display App', home: InputDisplayScreen(), ); } } class InputDisplayScreen extends StatefulWidget { @override _InputDisplayScreenState createState() => _InputDisplayScreenState(); } class _InputDisplayScreenState extends State { final TextEditingController _controller = TextEditingController(); String _displayText = ''; void _updateDisplay() { setState(() { _displayText = _controller.text; _controller.clear(); }); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Input Display'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextField( controller: _controller, decoration: InputDecoration(labelText: 'Enter text'), ), SizedBox(height: 20), ElevatedButton( onPressed: _updateDisplay, child: Text('Display Text'), ), SizedBox(height: 20), Text( 'You entered: $_displayText', style: TextStyle(fontSize: 18), ), ], ), ), ); } } ``` -------------------------------- ### Flutter API Call and Token Display Source: https://github.com/dhwani-19/fluttertask/blob/main/README.md Creates a Flutter screen with email and password TextFields and a submit button. Upon submission, it makes a POST API call to https://reqres.in/api/login with provided credentials. The fetched token is then passed to another screen for display. ```dart import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'API Login App', home: LoginScreen(), ); } } class LoginScreen extends StatefulWidget { @override _LoginScreenState createState() => _LoginScreenState(); } class _LoginScreenState extends State { final TextEditingController _emailController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); Future _login() async { final email = _emailController.text; final password = _passwordController.text; final response = await http.post( Uri.parse('https://reqres.in/api/login'), headers: { 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode({ 'email': email, 'password': password, }), ); if (response.statusCode == 200) { final data = jsonDecode(response.body); final token = data['token']; Navigator.push( context, MaterialPageRoute(builder: (context) => TokenDisplayScreen(token: token)), ); } else { // Handle login failure ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Login failed: ${response.statusCode}')), ); } } @override void dispose() { _emailController.dispose(); _passwordController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Login'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextField( controller: _emailController, decoration: InputDecoration(labelText: 'Email'), keyboardType: TextInputType.emailAddress, ), SizedBox(height: 10), TextField( controller: _passwordController, decoration: InputDecoration(labelText: 'Password'), obscureText: true, ), SizedBox(height: 20), ElevatedButton( onPressed: _login, child: Text('Submit'), ), ], ), ), ); } } class TokenDisplayScreen extends StatelessWidget { final String token; TokenDisplayScreen({required this.token}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Token Display'), ), body: Center( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'Your Token:', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), SizedBox(height: 10), Text( token, style: TextStyle(fontSize: 16), textAlign: TextAlign.center, ), ], ), ), ), ); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.