Skip to content

Unable to Change TextSelectionHandleColor using Theme Widget #34640

Description

@vijayaragavangkf

I am trying to change textSelectionColor and textSelectionHandleColor for particular TextField(not all). When I used Theme Widget as parent for that TextField it still uses the textSelectionHandleColor from MaterialApp. The textSelectionColor is woking fine.

Example Code:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Summa App",
      theme: ThemeData(
        textSelectionHandleColor: Colors.red,
      ),
      home: MyTextField(),
    );
  }
}

class MyTextField extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Builder(
          builder: (context2){
            return Theme(
              data: Theme.of(context2).copyWith(
                textSelectionHandleColor: Colors.green,  //Not being used
              ),
              child: TextField(),
            );
          },
        ),
      ),
    );
  }
}

Flutter Doctor:

[√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 10.0.16299.1087], locale en-IN)
    • Flutter version 1.5.4-hotfix.2 at D:\Installed\FlutterSDK
    • Framework revision 7a4c33425d (7 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\Flower\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.4)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 36.1.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!

Activity

  1. baderouaich commented on Jun 18, 2019

    @baderouaich

    You are using the wrong context, use context instead of context2.

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: "Summa App",
          theme: ThemeData(
            textSelectionHandleColor: Colors.red,
          ),
          home: MyTextField(),
        );
      }
    }
    
    class MyTextField extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Builder(
              builder: (context2){
                return Theme(
                  data: Theme.of(context).copyWith(
                    textSelectionHandleColor: Colors.green,  //Not being used
                  ),
                  child: TextField(),
                );
              },
            ),
          ),
        );
      }
    }
  2. added
    d: stackoverflowGood question for Stack Overflow
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    on Jun 18, 2019
  3. vijayaragavangkf commented on Jun 19, 2019

    @vijayaragavangkf
    Author

    @BaderEddineOuaich Thanks. But I already tried that. Still not working.

  4. LongCatIsLooong commented on Aug 1, 2019

    @LongCatIsLooong
    Contributor

    Closed #36313 because it breaks the current API and I'd expect this issue to be fixed once #36220 is fixed. Instead of breaking the API twice let's just fix the problem altogether. Closing in favor of #36220. If the fix I have for that issue doesn't work out then I'll reopen this issue.

  5. AlexV525 commented on Mar 8, 2020

    @AlexV525
    Member

    I hate to said that but is there any progress been made with #36220 or something else? Still not working with the latest release and those pull requests seems no one do care about...
    image
    Why this kind of issue (tiny one) can be last for so long and got almost no response? 😢
    cc @justinmc

  6. justinmc commented on Mar 16, 2020

    @justinmc
    Contributor

    @AlexVincent525 Can you post in #36220 with any additional info you have? If you have a possible solution, I'd be happy to help you get a PR merged.

  7. AlexV525 commented on Mar 17, 2020

    @AlexV525
    Member

    @justinmc There's an implement to allow user modify the whole text selection with ExtendedTextField. It's just not related to #36220 if we expose the textSelectionControl with TextField. Through extended the TextSelectionControls we can custom the handle or the toolbar. See https://github.com/fluttercandies/extended_text_field/blob/master/README.md#textselectioncontrols

  8. lock commented on Apr 2, 2020

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked and limited conversation to collaborators on Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions