Native text input from iOS for Flutter

Overview

Native Text Input for Flutter

A text input widget built using the native UITextView on iOS (this package only supports iOS for now).

Installation

Follow the instructions from https://pub.dev/packages/flutter_native_text_input/install

Why you should use this

Many iOS users are used to the subtle features provided by the native UITextView throughout iOS. Even though Flutter provides a lot of useful widgets, many Flutter developers will notice that TextField or CupertinoTextField provided by Flutter are not on par with their native counterpart.

The above shows just one of the missing text editing features in Flutter's TextField, when comparing to the native UITextView. Features like these are especially important if you're building an app that involves a lot of text composition (messaging, editing document, and so on).

To address this, this package simply wraps the native UITextView as a Flutter widget.

Hope you find it useful and happy coding! 🎉 🎉 🎉

Plugin API

Name Type Description Default
controller TextEditingController Controlling the text being edited (https://api.flutter.dev/flutter/material/TextField/controller.html) null
style TextStyle The style to use for the text being edited [Only fontSize, fontWeight, color are supported] (https://api.flutter.dev/flutter/painting/TextStyle-class.html) null
placeholderStyle TextStyle The style to use for the placeholder text. [Only fontSize, fontWeight, color are supported] (https://api.flutter.dev/flutter/painting/TextStyle-class.html) null
placeholder String Placeholder text when text entry is empty (https://api.flutter.dev/flutter/cupertino/CupertinoTextField/placeholder.html) null
textContentType TextContentType To identify the semantic meaning expected for a text-entry area (https://developer.apple.com/documentation/uikit/uitextcontenttype) null
keyboardAppearance Brightness The appearance of the keyboard (https://api.flutter.dev/flutter/material/TextField/keyboardAppearance.html) null
keyboardType KeyboardType Type of keyboard to display for a given text-based view (https://developer.apple.com/documentation/uikit/uikeyboardtype) KeyboardType.defaultType
onChanged ValueChanged Called when the user initiates a change to text entry (https://api.flutter.dev/flutter/material/TextField/onChanged.html) null
onSubmitted ValueChanged Called when the user indicates that they are done editing the text in the field (https://api.flutter.dev/flutter/material/TextField/onSubmitted.html) null
focusNode FocusNode Defines the keyboard focus for this widget (https://api.flutter.dev/flutter/material/TextField/focusNode.html) null
textAlign TextAlign How the text should be aligned horizontally (https://api.flutter.dev/flutter/material/TextField/textAlign.html) TextAlign.start
minLines int Minimum number of lines of text input widget 1
maxLines int Maximum number of lines of text input body, 0 for no limit 1

More examples

You may find more usage examples here.

Contributing

Found a bug?

Please do not hestitate to report that. This cuuld help improve this package.

Feature request?

Please feel free to create an issue.

Pull request?

Contributors are welcome. Just create a PR and it would be reviewed and merged ASAP.

If you enjoy using this package or it helps you or your team, you could also buy me a cup of coffee to show support :)

https://PayPal.Me/hkhenryleung

License

This project is licensed under the MIT License.

Comments
  • [BUG] BLUR : weird textfield ui render with back drop filter

    [BUG] BLUR : weird textfield ui render with back drop filter

    I want to display some blurred effect behind the textfield but there is a strange render :

    I set a red blur color for better seeing . Here is your NativeTextField with the blur :

    Capture d’écran 2021-12-04 à 15 41 15

    Here the NativeTextField without blur :

    Capture d’écran 2021-12-04 à 15 39 06

    Here is the Flutter text field with blur and the expected result :

    Capture d’écran 2021-12-04 à 15 40 53

    The sample code for this bottom Row :

    Align(
          alignment: Alignment.bottomCenter,
          child: Stack(
            alignment: Alignment.bottomCenter,
            children: [
              ClipRect(
                child: BackdropFilter(
                    filter: ImageFilter.blur(sigmaX: 15, sigmaY: 15),
                    child: Container(
                      color: ThemeProvider.instance.getBlurScaffoldColor(context),
                      padding: EdgeInsets.only(top: paddingChat, bottom: paddingChat),
                      child: SafeArea(
                        top: false,
                        child: Container(
                          height: chatHeight,
                        ),
                      ),
                    )),
              ),
              SafeArea(
                top: false,
                child: Row(
                  children: [
                    Container(
                      height: chatHeight,
                      width: chatHeight,
                      margin: const EdgeInsets.only(left: 10, right: 10),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          border: Border.all(color: chatColor, width: 0.8),
                          shape: BoxShape.circle),
                      child: GestureDetector(
                          onTap: () {
                            onCameraTap();
                          },
                          child: Icon(CupertinoIcons.camera_circle_fill,
                              color: chatColor, size: 35)),
                    ),
                    Expanded(
                      child: Platform.isAndroid
                          ? androidTextField()
                          : iosTextField(),
                    ),
                    Container(
                      margin: const EdgeInsets.only(left: 10, right: 10),
                      height: chatHeight,
                      width: chatHeight,
                      padding: const EdgeInsets.all(2),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          border: Border.all(color: chatColor, width: 0.8),
                          shape: BoxShape.circle),
                      child: GestureDetector(
                        //onTap: onGalleryTap,
                        child: FirstGalleryAsset(
                            width: chatHeight,
                            height: chatHeight,
                            circle: true),
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        );
    

    I first wrapped the entire row as back drop filter child and then tried to put them into a stack to workaround in order to overlay widgets but no result ...

    Native Text field :

    NativeTextInput(
          returnKeyType: ReturnKeyType.send,
          cursorColor: ThemeProvider.colorApp1,
          textCapitalization: TextCapitalization.sentences,
          style: Theme.of(context).textTheme.bodyText1,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(chatHeight / 2),
              border: Border.all(color: chatColor, width: 0.8)),
          placeholderStyle: ThemeProvider.instance.getPlacerHolderStyle(),
          placeholder: 'message',
          //Localization.of(context)!.getText("write_new_message"),
          onSubmitted: (String? value) {
            print("submitted value : $value");
            if (value != null && value.trim().isNotEmpty) {
              sendNewMessage(value.trim());
              messagesViewModel.saveTyping(typing: false);
            }
          },
          keyboardAppearance: Theme.of(context).brightness,
          focusNode: focusNode,
          minLines: 1,
          maxLines: 3,
          onChanged: (value) {
            if (value.isNotEmpty) {
              messagesViewModel.saveTyping(typing: true);
            } else if (value.isEmpty) {
              messagesViewModel.saveTyping(typing: false);
            }
          },
          controller: textEditingController,
        );
    

    Sorry for the code no runnable quickly I'm hard at work right now.

    Could you help me fix this ? Thank you

    question 
    opened by Nico3652 3
  • [BUG] Placer Holder value submitted

    [BUG] Placer Holder value submitted

    First problem, when I'm closing the keyboard by touching outside the onSubmitted callback is fired and don't know why.

    Second, when the field is empty, my place holder value is submitted :

    placeholder: 'message',
    onSubmitted: (String? value) {
      print("submitted value : $value");
    },
    

    Result

    flutter: submitted value : message
    

    Third, when I'm submitted the textfield config is not reset : ex : If I wrote 3 lines and submit the place holder is not printed again and the 3 lines config is remaining :

    Capture d’écran 2021-12-03 à 14 44 44

    Thanks in advance

    opened by Nico3652 3
  • Custom font name on iOS, Flutter 3 support

    Custom font name on iOS, Flutter 3 support

    • Support for custom font name on iOS.
    • Add Flutter 3 support

    Originally I was using fontFamily to pass the font name, but there's some nuance to converting a font family to a font name and it's platform-specific to iOS. I'm passing fontName as a separate iOS option for now, so there's no ambiguity that the developer is expected to include weight information in the name.

    Fixes https://github.com/henryleunghk/flutter-native-text-input/issues/33 Fixes https://github.com/henryleunghk/flutter-native-text-input/issues/37

    Screen Shot 2022-06-16 at 12 43 00 PM
    opened by collinjackson 2
  • Feature request: customize the font size and family

    Feature request: customize the font size and family

    First of all, thanks for the package! I'm glad it exists and appreciate your work.

    The consistency in font styles is very important for me (and, perhaps, many others), so it would be very good to be able to customize them. I personally don't mind manually putting the required TTF in ios/android directories of projects where this plugin is used.

    opened by f-person 2
  • Use `attributedPlaceholder` for placeholder text

    Use `attributedPlaceholder` for placeholder text

    • Use attributedPlaceholder instead of editing the text in the UITextView. This allows the text to be shown when the field is selected.
    • Avoid BoxConstraints errors when the max height is not valid.
    • Updated the State to mutate the state object inside setState.
    • Add files to .gitignore that should not be checked in to source control.

    Fixes #29

    Screen recording of built-in example:

    https://user-images.githubusercontent.com/394889/159203300-75489b6d-dbae-4539-aae0-f36e9b10db54.mov

    Screen recording of indjec/native-text-field demo:

    https://user-images.githubusercontent.com/394889/159539620-787363af-1c3a-45db-8138-2eb15b52e22f.mp4

    opened by collinjackson 2
  • PlaceHolderStyle more useful than placeholderColor

    PlaceHolderStyle more useful than placeholderColor

    Hello and thanks for the updates on the package :)

    It was nice to be able to to set the placeholderStyle with a specific TextStyle, rather than simply the color.
    Is it possible to have it back ? Or add a placeHolderFonts property for example ? (that would allow to set anything we want from TextStyle fonts (size, family...)

    Thanks !

    opened by Tom3652 2
  • [IMPROVEMENT]  Keyboard moving down/up when trying to keep focus

    [IMPROVEMENT] Keyboard moving down/up when trying to keep focus

    This method FocusScope.of(context).requestFocus(focusNode); to keep focus when I press 'action button' make the keyboard moving down/up fast.

    I tried this code on the TextField & CupertinoTextField and I think this is working much better :

    " The cleanest approach would be to use onEditingComplete() with TextEditingController instead of onSubmitted(text). Refer below example.

      final _controller = TextEditingController();
      TextField(
           controller: _controller,
           padding: EdgeInsets.all(8),
           textInputAction: TextInputAction.send,
           placeholder: 'Type your message',
           onEditingComplete: (){
               if (_controller.text.isEmpty) return;
    
               sendMessage(_controller.text);
           },
      ),
    

    "

    Found on stackOverFlow.

    Do you think you could try this with the native ?

    opened by Nico3652 2
  • [BUG] Place holder not working

    [BUG] Place holder not working

    I'm facing weird behavior using the place holder.

    • It can be remove in loop
    • It can be retrieved and sent with onSubmitted

    Here is the behavior :

    Enregistrement de l’écran 2021-12-04 à 15 30 19

    Thanks in advance for fix

    opened by Nico3652 2
  • [Feature Request] More parameters to customize

    [Feature Request] More parameters to customize

    Thanks for the package. Please add more parameters for customization as we could set in the native code :

    In my case, Tint color , Return Key , Capitalization...

    Capture d’écran 2021-12-01 à 18 19 51

    And from the CupertinoTextField :

    • maxLines
    • suffix widget
    • prefix widget
    opened by Nico3652 2
  • [Feature Request] Support Android native text field

    [Feature Request] Support Android native text field

    In order to gain popularity for this library, it would be great to extend support for Android text input.

    Do you foresee any challenges to include Android too?

    opened by ken-ng-esotec 2
  • Works also on the Text Widget

    Works also on the Text Widget

    im trying to achieve it also on Text Widget, planning to look like this:

    image

    its works only on the NativeTextInput but not on the Text Widget. Any idea how to make it work?

    opened by shinroketore 2
  • Cursor cannot be dragged (iOS 16.2)

    Cursor cannot be dragged (iOS 16.2)

    Here's a video from the iPhone Simulator:

    https://user-images.githubusercontent.com/37193648/210152606-dfbd2768-c1da-4f92-bbf2-a0bb23057b5c.mov

    The issue also persisted on my physical mobile (iPhone 11, iOS 16.2).

    Details:

    • I can double tap to bring up the iOS text input options menu.
    • I can tap anywhere within the text input to change the cursor position.
    • I can long press the keyboard spacebar and move my finger around to change the cursor position.
    • But what I cannot do is press and hold my finger on the cursor and then move the cursor around

    I would be very grateful if this could be fixed soon, otherwise the package isn't all-the-way native!

    opened by kevgug 1
  • Support for UITextInputMode on iOS?

    Support for UITextInputMode on iOS?

    I wonder if there will be support for UITextInputMode. It could be very useful to specify emoji keyboard and also to remember the user's choice of input language in the app.

    Thank you for the great project by the way!

    opened by shenghan97 0
  • (controller , rebuild, focus ) issues

    (controller , rebuild, focus ) issues

    Hi, thanks for the package !
    seems like there is couple of issues i found :

    1. when provide own controller, its not showing position of the cursor (controller.selection.base.offset) always show -1 value
    2. if return key set as DefaultValue, creation a new line will set the cursor at the end of the text length , despite sometimes it works correctly , but in most cases behavior is wrong (when try to create a new line somewhere in the middle ).
    3. and the last one : rebuild widget, which contains the Native Text Input widget not update the last one, i mean if there is any variable , which change the font size , for example, the build method gets called. but value inside the widget seems not update the font size. despite it changed .
    opened by Hlebkuznetsov 1
  • Max height should be an integer number of lines

    Max height should be an integer number of lines

    You can have a line be partially visible if you're overflowing the container.

    This video is based on the demo code in https://github.com/indjec/native-text-field

    https://user-images.githubusercontent.com/394889/159553998-03b6b19b-12bf-4a68-acb7-e759470fe05e.mov

    It seems to be some issue with the computation of _maxHeight.

    In my testing, adding 13 to the value of maxLineHeight helped. Here's a code sample:

    https://github.com/collinjackson/flutter-native-text-input/tree/padding-fix

    After the change:

    https://user-images.githubusercontent.com/394889/159556049-3f9d1689-bcba-4435-9826-c654abd99aee.mov

    However, there are still problems if text overflows a line, as shown here:

    https://user-images.githubusercontent.com/394889/160070603-d88650b7-1116-40c8-aa29-080444a829d6.mov

    Related StackOverflow question

    opened by collinjackson 0
Releases(2.2.0)
Owner
Henry Leung
An experienced software engineer specialized in native iOS, native Android and also cross-platform mobile app development with Flutter or React-Native.
Henry Leung
With flutter tags you can create selectable or input tags that automatically adapt to the screen width

flutter_tags Create beautiful tags quickly and easily. Installing Add this to your package's pubspec.yaml file: dependencies: flutter_tags: "^0.4.9+

Antonino Di Natale 417 Dec 21, 2022
Native context menu for Flutter apps

native_context_menu Native context menu for flutter apps Installation flutter pub add native_context_menu Usage import 'package:native_context_menu/na

Andrei Lesnitsky 151 Dec 22, 2022
This Dart package offers developers a streamlined library of Flutter widgets, useful for expanding widgets and text views, when users interact with them.

This Dart package offers developers a streamlined library of Flutter widgets, useful for expanding widgets and text views, when users interact with them.

Jesús Rodríguez 44 Dec 6, 2022
The best swiper for flutter , with multiple layouts, infinite loop. Compatible with Android & iOS.

The best swiper for flutter , with multiple layouts, infinite loop. Compatible with Android & iOS.

null 3.4k Jan 3, 2023
The most complete flutter plugin packages for open various settings screen in Android and Ios

open_settings The most complete flutter plugin packages for open various settings screen in Android and Ios For Android: this plugin currently support

Ali Hoseinpoor 15 Dec 11, 2022
A small attempt to make an e-commerce user interface in Flutter for Android and iOS.

Flutter ecommerce App A small attempt to make an e-commerce user interface in Flutter for Android and iOS. I developed this application just for learn

Md Tarikul Islam 615 Jan 3, 2023
Instagram UI designed with Flutter; it is compatible and responsive with any type of Android and iOS devices.

instagram Instagram clone UI designed with Flutter; it is compatible and responsive with any type of Android and iOS devices . Getting Started This pr

Mustafa Nabavi 4 Oct 28, 2021
Flutter YouTube UI - Web & Mobile: Android | IOS

YouTube Clone UI - Flutter Mobile: IOS | Android Mobile Version: Android | IOS @luanbatistadev Open Source Copyright © 2021-present, Luan Batista. Fac

Luan Batista 5 Sep 22, 2022
A nice clean onboarding screen for your e-commerce app that can run both Andriod and iOS devices because it builds with flutter

A nice clean onboarding screen for your e-commerce app that can run both Andriod and iOS devices because it builds with flutter

null 23 Dec 4, 2022
A Flutter plugin for iOS and Android for generating sign-in buttons for different social media account.

A Flutter plugin for iOS and Android for generating sign-in buttons for different social media account.

Julian Steenbakker 6 Nov 6, 2022
E-commerce UI concept in Flutter for Android and iOS, this application just for learning purposes.

E-commerce UI concept in Flutter for Android and iOS, this application just for learning purposes. There are over 20 screen variations.

Pronab Sen Gupta 2 Nov 12, 2022
An android/ios E-commerce application developed for local retailers and businesses.

flutterapp A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

null 0 Dec 28, 2021
Movies App UI in Flutter using Simple Widgets without Using API's in Flutter.

Movies App UI in Flutter using Simple Widgets without Using API's in Flutter.

Habib ullah 3 May 15, 2022
A flutter plugin for Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple.

A flutter plugin for Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple.

Urmish Patel 191 Dec 29, 2022
The Coolicons icon pack for Flutter with over 400 icons available for your flutter project.

coolicons This flutter package allows you to use the Coolicons icon pack. Made from Coolicons. ?? Installation In the dependencies: section of your pu

Stephen Joel 1 May 24, 2022
Foody - Flutter project to display foods to clients and display charts and has a lot of features , two flutter apps : Android and Web

Foody Flutter project to display foods to the clients and use charts and use a lot of features to complete the process (HUGE APP) There two apps: Andr

ABDULKARIMALBAIK 1 Feb 7, 2022
Flutter-business-card-app - Flutter + Dart business card mobile app

Dart + Flutter Business Card Mobile Application

Mark Hellner 1 Nov 8, 2022
A Flutter project that gives basic flutter design to implement a login UI

Login UI Design A Flutter project that gives basic flutter design to implement a

CABREX 9 Nov 8, 2022
Flutter Complete E-Commerce app (UI by - 'The Flutter Way')

NOT COMPLETED YET! e_commerce A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to ge

null 1 Mar 8, 2022