skip to Main Content

I’m trying to fill in sqflite tables using textfields, but it creates a separate table instead of filling in the various fields

class _InputBarState extends State<InputBar> {
  final _controller = TextEditingController();
  final _controller1 = TextEditingController();
  final _controller2 = TextEditingController();
  final _focusNode = FocusNode();

  String get text => _controller.text.trim();
  String get qnt => _controller1.text.trim();
  String get um => _controller2.text.trim();

TextField(
controller: _controller,
),

TextField(
controller: _controller1,
),

TextField(
controller: _controller2,
),

IconButton(
                  color: primaryColor,
                  padding: const EdgeInsets.only(right: 10),
                  icon: const Icon(Icons.add),
                  onPressed: text.isEmpty || um.isEmpty || qnt.isEmpty  ? null : () => _onSubmitted(text, um, qnt),
                ),

  void _onSubmitted(String text, String qnt, String um) {
    if (text.isEmpty || qnt.isEmpty || um.isEmpty) return;

    widget.onSubmitted(text);
    widget.onSubmitted(qnt);
    widget.onSubmitted(um);
    _controller.clear();
    _controller1.clear();
    _controller2.clear();
    _focusNode.requestFocus();
  }

if I fill in the 3 fields with: 1, 2, 3, I have the attached image as output..
instead it should be a single line like: 1 2 3

Text(item.name + item.qnt + item.um ),

help to solve this problem

2

Answers


  1. Chosen as BEST ANSWER

    with your modification I get this error

    immage

    Future<String> createItem(String listId, String name, String qnt, String um) async {
    final id = uuid();
    final maxPosition = (await _crdt.query('''
      SELECT max(position) AS max_position FROM todos
      WHERE list_id = ? AND is_deleted = 0
    ''', [listId])).first['max_position'] as int? ?? -1;
    await _crdt.execute('''
      INSERT INTO todos (id, list_id, name, qnt, um, done, position, creator_id, created_at)
      VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)
    ''', [
      id,
      listId,
      name,
      qnt,
      um,
      0,
      maxPosition + 1,
      userId,
      DateTime.now().toUtcString,
    ]);
    return id;
    

    }


  2. Your provided code is not enough to clarify the problem. It would be great if you can provide code snippet of the widget.onSubmitted(text) callback.

    But assuming you want to store the text, qnt and um value in a single row, you have to change the callback to something like the following instead of calling it individually with text, qnt, um:

    widget.onSubmitted(text: text, qnt: qnt, um: um)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search