• Taha Tesser's avatar
    Fix `cursorColor` with an opacity is not respected (#133548) · f32b6fed
    Taha Tesser authored
    fixes [`cursorColor` with an opacity  is not respected](https://github.com/flutter/flutter/issues/132886)
    
    <details>
    <summary>expand to view the code sample</summary> 
    
    ```dart
    import "package:flutter/material.dart";
    // import "package:flutter/scheduler.dart";
    
    // final color = Colors.red;
    const color = Color(0x55ff0000);
    
    void main() {
      // timeDilation = 4;
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Example(),
        );
      }
    }
    
    class Example extends StatefulWidget {
      const Example({super.key});
    
      @override
      State<Example> createState() => _ExampleState();
    }
    
    class _ExampleState extends State<Example> {
      late FocusNode _focusNode;
      late TextEditingController _controller;
    
      @override
      void initState() {
        super.initState();
        _focusNode = FocusNode();
        _controller = TextEditingController(text: 'Hello World');
      }
    
      @override
      void dispose() {
        _focusNode.dispose();
        _controller.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        const bool cursorOpacityAnimates = false;
        double cursorWidth = 6;
    
        return Scaffold(
    
          body: Center(
            child: Padding(
              padding: const EdgeInsets.symmetric(
                horizontal: 16,
              ),
              child: Column(
                children: <Widget>[
                  const Spacer(),
                  const Text('EditableText'),
                  const SizedBox(height: 8),
                  InputDecorator(
                    decoration: InputDecoration(
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(8),
                      ),
                    ),
                    child: EditableText(
                      cursorColor: color,
                      cursorWidth: cursorWidth,
                      cursorOpacityAnimates: cursorOpacityAnimates,
                      focusNode: _focusNode,
                      controller: _controller,
                      style: Theme.of(context).textTheme.bodyLarge!,
                      backgroundCursorColor: Colors.amber,
                      onSubmitted: (String value) {
                        // Add your code here.
                      },
                    ),
                  ),
                  const Spacer(),
                  const Text('TextField'),
                  const SizedBox(height: 8),
                  TextField(
                    cursorColor: color,
                    cursorWidth: cursorWidth,
                    cursorOpacityAnimates: cursorOpacityAnimates,
                    controller: _controller,
                    focusNode: _focusNode,
                    onSubmitted: (String value) {
                      // Add your code here.
                    },
                  ),
                  const Spacer(),
                ],
              ),
            ),
          ),
        );
      }
    }
    ```
    
    </details>
    
    ### Before
    
    ![Screenshot 2023-08-29 at 14 57 57](https://github.com/flutter/flutter/assets/48603081/cd55bb74-23b8-4980-915d-f13dee22a50f)
    
    ### After
    ![Screenshot 2023-08-29 at 14 58 20](https://github.com/flutter/flutter/assets/48603081/c94af4e3-f24b-44e7-bbed-7c6c21e90f2a)
    f32b6fed
Name
Last commit
Last update
.github Loading commit data...
.vscode Loading commit data...
bin Loading commit data...
dev Loading commit data...
examples Loading commit data...
packages Loading commit data...
.ci.yaml Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CODEOWNERS Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE Loading commit data...
PATENT_GRANT Loading commit data...
README.md Loading commit data...
TESTOWNERS Loading commit data...
analysis_options.yaml Loading commit data...
dartdoc_options.yaml Loading commit data...
flutter_console.bat Loading commit data...