Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – how set data of virtual keyboard in textfield flutter

Posted on November 11, 2022 By

Solution 1 :

When the onKeyPress callback get fired, you can set the text using the pinNumber text controller.

Problem :

How i get focus of virtual keyboard rather than normal keyboard on textfiled .
heres the code

import 'dart:async';
import 'package:android/GlobalVariables.dart' as globals;
import 'package:flutter/material.dart';
import 'package:localstorage/localstorage.dart';
import 'Confirm.dart';
import 'package:virtual_keyboard/virtual_keyboard.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/services.dart';
import 'HomeScreen.dart';

    void bh(context) async {
      var connectivityResult = await (Connectivity().checkConnectivity());
      if (connectivityResult == ConnectivityResult.mobile) {
        print("Connected to Mobile Network");
      } else if (connectivityResult == ConnectivityResult.wifi) {
        print("Connected to WiFi");
      } else {
        showDialog(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: Center(
                  child: Text(
                    "Connectivity ",
                    style: TextStyle(fontSize: 15),
                  ),
                ),
                actions: <Widget>[
                  Center(
                      child: Text(
                    "Please Check your Internet Connection",
                    style: TextStyle(fontSize: 15),
                  )),
                  FlatButton(
                    child: Text(
                      'ok',
                      style: TextStyle(fontSize: 15),
                    ),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              );
            });
      }
    }

    class DashboardScreen extends StatefulWidget {
      @override
      _DashboardScreenState createState() => new _DashboardScreenState();
    }

    class _DashboardScreenState extends State<DashboardScreen> {
      final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
      LocalStorage userKey = new LocalStorage('userKey');
      TextEditingController pinNumber = new TextEditingController();

      bool hasKey;
      var userKeyValue;

      void showInSnackBar(String message) {
        scaffoldKey.currentState.showSnackBar(SnackBar(content: Text(message)));
      }

      @override
      void initState() {
        super.initState();
        bh(context);
      }

      void checkKey() async {
        userKeyValue = await userKey.getItem('userKey');
        print(userKeyValue);
        if (userKeyValue == null) {
          hasKey = false;
        } else {
          hasKey = true;
        }
      }

      void sendDataNav(BuildContext context) {
        String textToSend = pinNumber.text;

        Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => Confirm(text: textToSend),
            ));
      }

      var study_no;
      var select_mon;
      LocalStorage mon = LocalStorage('mon');
      LocalStorage studyNumber = LocalStorage('UserstudyNumber');
      void start(context) async {
        select_mon = DateTime.now().toString().substring(5, 7);
        print("study number $study_no");
        if (study_no == null) {
          print("in $study_no");
          Future.delayed(Duration.zero, () {
            Navigator.pushNamed(context, '/setting');
          });
        } else {
          print(select_mon);
          Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => HomeScreen(stu: study_no, mon: select_mon),
              ));
        }
      }

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          resizeToAvoidBottomPadding: false,
          key: scaffoldKey,
          body: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                Container(
                  height: MediaQuery.of(context).size.height / 2.5,
                  width: MediaQuery.of(context).size.width,
                  color: globals.primaryColor,
                  child: Image.asset('image/asset/Logob.png'),
                ),
                Padding(
                  padding: const EdgeInsets.all(15.0),
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    child: TextField(
                      controller: pinNumber,
                      style: new TextStyle(
                        fontSize: 20.0,
                      ),
                      decoration: InputDecoration(
                        contentPadding: const EdgeInsets.symmetric(
                            vertical: 10, horizontal: 20),
                        border: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.green, style: BorderStyle.solid),
                          borderRadius: new BorderRadius.horizontal(),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: globals.primaryColor,
                              style: BorderStyle.solid),
                          borderRadius: new BorderRadius.horizontal(),
                        ),
                        //icon: Icon(Icons.calendar_today,),
                        hintText: 'PIN', suffixStyle: TextStyle(fontSize: 10),
                        labelText: 'Enter Your Pin',
                      ),

                      // Navigator.pushNamed(context,  '/afterCalender')
                      // keyboardType: TextInputType.number,
                      // autofocus: true,
                      onSubmitted: (ss) async {
                        if (pinNumber.text.length < 1) {
                          showInSnackBar("Enter Pin");
                          print('invalid');
                          return;
                        }
                        userKeyValue = await userKey.getItem('userKey');
                        if (userKeyValue == null) {
                          hasKey = false;
                        } else {
                          hasKey = true;
                        }
                        if (hasKey) {
                          if (userKeyValue != pinNumber.text) {
                            // show error message
                            showInSnackBar("Wrong Pin");
                            print('not valid');
                          } else {
                            print('valid');
                            study_no =
                                studyNumber.getItem('UserstudyNumber').toString();
                            start(context);
                            showInSnackBar("Sucessful");
                          }
                        } else {
                          if (pinNumber.text.length != 4) {
                            showInSnackBar("Enter Pin of 4 Numbers");
                            // show error message of length
                            print('hello');
                          } else {
                            setState(() {
                              sendDataNav(context);
                            });
                            // userKey.setItem('userKey', pinNumber.text);
                          }
                        }
                      },
                    ),
                  ),
                ),
                VirtualKeyboard(
                    height: 300,
                    fontSize: 15,
                    textColor: Colors.black,

                    type: VirtualKeyboardType.Numeric,
                    onKeyPress: (key) => print(key.text)),
              ],
            ),
          ),
        );
      }
    }

How i get focus of virtual keyboard rather than normal keyboard on textfiled .
onclick on textfiled i want system keyboard disabled and virtual keyboard to get focus and allow to add data………………………………………………………………………………………………………………………………………………………………………………………………..

READ  [FIXED] android - Google Play Console Data Safety No data collected
Powered by Inline Related Posts

Comments

Comment posted by Darish

on your emulator settings, you can select whether to use virtual keyboard or not.

Comment posted by Karan Rnd

its not about emulator , i want a fixed keyboard which is added as a widget VirtualKeyboard in Code.

Comment posted by Darish

well then, set the text on your desired text widget when the onKeyPress: event get fired.

Comment posted by Karan Rnd

I am fresher Can you please elaborate with code

Comment posted by Darish

in the onKeyPress callback you can set the text using the pinNumber text controller.

Android Tags:android, dart, flutter, flutter-layout, keyboard

Post navigation

Previous Post: [FIXED] java – How to solve debug issue
Next Post: [FIXED] android – How to solve setting up this payment problem – paypal

Related Posts

[FIXED] flutter – I can’t run emulator in android studio Android
[FIXED] need to convert following Signnature verification python code to Android? Android
[FIXED] android – Link a JSON file and a java file Android
[FIXED] layout – Binary XML file line #28: Error inflating class android.widget.TextView Android
[FIXED] android – App icon not displaying when application goes to background Android
[FIXED] java – Sort array of different types of objects Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Which is stronger 19 gauge or 23 gauge?
  • Does BMW still use GM transmissions?
  • Is primary or secondary market research better?
  • What does it mean when ADT says low battery?
  • Can a baby sleep on a regular mattress?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme