/
123321
/
sheet
Обзор
Документация
Войти
/
123321
/
sheet
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
main.dart
90 строк
2 KB
123321
create main.dart
20 окт 2024, 17:19
20 окт 2024, 17:19
817b169
Код
Авторство
О чём код?
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } // ignore: use_key_in_widget_constructors class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: _CounterPage(), ); } } class _CounterPage extends StatefulWidget { @override _CounterPageState createState() => _CounterPageState(); } class _CounterPageState extends State<_CounterPage> { List<int> _counts = [0]; // Список для хранения значений счетчиков void _addCounter() { setState(() { _counts.add(0); // Добавляем новый счетчик }); } void _increment(int index) { if (_counts[index] < 100) { setState(() { _counts[index]++; }); } } void _decrement(int index) { if (_counts[index] > 0) { setState(() { _counts[index]--; }); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Counter App')), body: ListView.builder( itemCount: _counts.length, itemBuilder: (context, index) { return Card( margin: EdgeInsets.all(8.0), child: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisSize: MainAxisSize.min, children: [ Text( '${_counts[index]}', style: const TextStyle(fontSize: 48), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ FloatingActionButton( onPressed: () => _decrement(index), child: const Icon(Icons.remove), ), FloatingActionButton( onPressed: () => _increment(index), child: const Icon(Icons.add), ), ], ), ], ), ), ); }, ), floatingActionButton: FloatingActionButton( onPressed: _addCounter, child: const Icon(Icons.add), ), ); } }