• 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
..
animation Loading commit data...
cupertino Loading commit data...
foundation Loading commit data...
gestures Loading commit data...
material Loading commit data...
painting Loading commit data...
physics Loading commit data...
rendering Loading commit data...
scheduler Loading commit data...
semantics Loading commit data...
services Loading commit data...
widgets Loading commit data...
dart_plugin_registrant.dart Loading commit data...