我有一个标记输入表单。所以我必须在每个文本字段中保存不同的标记。试过控制器,但不起作用。如果你有任何soulusion请帮助。截图:https://ibb.co/CbsBQMy
kq0g1dla1#
为每个标记创建不同的控制器,并将其放置在末尾
import 'package:flutter/material.dart'; class MarkEntryForm extends StatefulWidget { const MarkEntryForm({super.key}); @override _MarkEntryFormState createState() => _MarkEntryFormState(); } class _MarkEntryFormState extends State<MarkEntryForm> { final TextEditingController _mathsController = TextEditingController(); final TextEditingController _scienceController = TextEditingController(); final TextEditingController _englishController = TextEditingController(); double _mathsMark = 0; double _scienceMark = 0; double _englishMark = 0; void _saveMarks() { _mathsMark = double.parse(_mathsController.text); _scienceMark = double.parse(_scienceController.text); _englishMark = double.parse(_englishController.text); // Save the marks to the database or do other processing here } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Mark Entry Form'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ TextField( controller: _mathsController, keyboardType: TextInputType.number, decoration: const InputDecoration( labelText: 'Maths', ), ), TextField( controller: _scienceController, keyboardType: TextInputType.number, decoration: const InputDecoration( labelText: 'Science', ), ), TextField( controller: _englishController, keyboardType: TextInputType.number, decoration: const InputDecoration( labelText: 'English', ), ), const SizedBox(height: 16), ElevatedButton( onPressed: _saveMarks, child: const Text('Save Marks'), ), ], ), ), ); } }
这是一个存储一组标记的示例程序,您可以将其更改为LIST以存储更多数据,也可以使用listview.builder来显示它
1条答案
按热度按时间kq0g1dla1#
为每个标记创建不同的控制器,并将其放置在末尾
这是一个存储一组标记的示例程序,您可以将其更改为LIST以存储更多数据,也可以使用listview.builder来显示它