Запретить отображение мягкой клавиатуры с текстом редактирования во флаттереAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Гость
 Запретить отображение мягкой клавиатуры с текстом редактирования во флаттере

Сообщение Гость »


I'm trying to use an android device that has an integrated barcode scanner. I have an textfield that is filled with the data read by the scanner. It's working bu everytime I change the focus, the soft keyboard shows up and I don't know how to hide it. This is my code:

import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'libr.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'TEST', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange), useMaterial3: true, ), home: const MyHomePage(), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { final _controller = TextEditingController(); late FocusNode _focusNode; String _message = ''; @override void initState() { super.initState(); _focusNode = FocusNode(); WidgetsBinding.instance.addPostFrameCallback((_) async { FocusScope.of(context).requestFocus(_focusNode); }); _focusNode.addListener(() { print('1: ${_focusNode.hasFocus}'); if (!_focusNode.hasFocus) { print('request!'); _focusNode.requestFocus(); print('requested'); } SystemChannels.textInput.invokeMethod('TextInput.hide'); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text("TEST"), ), body: Center( child: Padding( padding: const EdgeInsets.all(8.0), child: Stack( children: [ TextField( // keyboardType: TextInputType.none, focusNode: _focusNode, controller: _controller, onChanged: (v) { _message = v; _controller.text = ''; setState(() {}); }, ), // Container( // color: Colors.white, // width: double.infinity, // height: double.infinity, // ), Text(_message), ], ), ), )); } } I try to solve it by setting the textfield read-only or setting the input type to none, but both didn't work.

Right now, every time I hide the keyboard, the focus changes and the the keyboard appear again... I'm stuck in a loop.

Edit Also, the ultimate goal is to hide the text field somehow... Maybe with a stack view and a container full screen above it.


Источник: https://stackoverflow.com/questions/781 ... in-flutter
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»