• Taha Tesser's avatar
    Fix `InputDecoration.applyDefaults` ignoring some properties (#129010) · 165d2377
    Taha Tesser authored
    fixes [`InputDecoration.applyDefaults` ignores some properties](https://github.com/flutter/flutter/issues/127330)
    
    <details> 
    <summary>code sample</summary> 
    
    ```dart
    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData(useMaterial3: true),
          home: const Example(),
        );
      }
    }
    
    class Example extends StatelessWidget {
      const Example({super.key});
    
      @override
      Widget build(BuildContext context) {
        const TextStyle textStyle = TextStyle(color: Color(0xFF00FFFF));
        const Color color = Color(0xFF00FF00);
        const InputBorder inputBorder = OutlineInputBorder(
          borderSide: BorderSide(
            color: Color(0xFF0000FF),
          ),
        );
    
        final InputDecoration appliedDefaults =
            const InputDecoration().applyDefaults(
          const InputDecorationTheme(
            labelStyle: textStyle,
            floatingLabelStyle: textStyle,
            helperStyle: textStyle,
            helperMaxLines: 2,
            hintStyle: textStyle,
            errorStyle: textStyle,
            errorMaxLines: 2,
            floatingLabelBehavior: FloatingLabelBehavior.never,
            floatingLabelAlignment: FloatingLabelAlignment.center,
            isDense: true,
            contentPadding: EdgeInsets.all(1.0),
            iconColor: color,
            prefixStyle: textStyle,
            prefixIconColor: color,
            suffixStyle: textStyle,
            suffixIconColor: color,
            counterStyle: textStyle,
            filled: true,
            fillColor: color,
            focusColor: color,
            hoverColor: color,
            errorBorder: inputBorder,
            focusedBorder: inputBorder,
            focusedErrorBorder: inputBorder,
            disabledBorder: inputBorder,
            enabledBorder: inputBorder,
            border: InputBorder.none,
            alignLabelWithHint: true,
            constraints: BoxConstraints(
                minWidth: 10, maxWidth: 20, minHeight: 30, maxHeight: 40),
          ),
        );
    
        return Scaffold(
          appBar: AppBar(
            title: const Text('InputDecoration().applyDefaults'),
          ),
          // Centered FilledButton.
          body: Center(
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  ColoredBox(
                    color: appliedDefaults.labelStyle.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.labelStyle.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.floatingLabelStyle
                            .toString()
                            .contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.floatingLabelStyle.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.helperStyle.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.helperStyle.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.hintStyle.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.hintStyle.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.errorStyle.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.errorStyle.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.iconColor.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.iconColor.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.prefixStyle.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.prefixStyle.toString()),
                  ),
                  ColoredBox(
                    color:
                        appliedDefaults.prefixIconColor.toString().contains('null')
                            ? Colors.red
                            : Colors.green,
                    child: Text(appliedDefaults.prefixIconColor.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.suffixStyle.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.suffixStyle.toString()),
                  ),
                  ColoredBox(
                    color:
                        appliedDefaults.suffixIconColor.toString().contains('null')
                            ? Colors.red
                            : Colors.green,
                    child: Text(appliedDefaults.suffixIconColor.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.counterStyle.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.counterStyle.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.fillColor.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.fillColor.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.focusColor.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.focusColor.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.hoverColor.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.hoverColor.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.errorBorder.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.errorBorder.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.focusedBorder.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.focusedBorder.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.focusedErrorBorder
                            .toString()
                            .contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.focusedErrorBorder.toString()),
                  ),
                  ColoredBox(
                    color:
                        appliedDefaults.disabledBorder.toString().contains('null')
                            ? Colors.red
                            : Colors.green,
                    child: Text(appliedDefaults.disabledBorder.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.enabledBorder.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.enabledBorder.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.border.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.border.toString()),
                  ),
                  ColoredBox(
                    color: appliedDefaults.constraints.toString().contains('null')
                        ? Colors.red
                        : Colors.green,
                    child: Text(appliedDefaults.constraints.toString()),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
    ``` 
    	
    </details>
    
    ### Before
    
    ![before screenshot](https://github.com/flutter/flutter/assets/48603081/ae564e15-4029-4feb-810f-e46b9312a257)
    
    ### After
    ![after screenshot](https://github.com/flutter/flutter/assets/48603081/8924a1d8-ffde-494b-bf44-66dab4d28845)
    165d2377
Name
Last commit
Last update
..
fix_data Loading commit data...
src Loading commit data...
analysis_options.yaml Loading commit data...
analysis_options_user.yaml Loading commit data...
animation.dart Loading commit data...
cupertino.dart Loading commit data...
foundation.dart Loading commit data...
gestures.dart Loading commit data...
material.dart Loading commit data...
painting.dart Loading commit data...
physics.dart Loading commit data...
rendering.dart Loading commit data...
scheduler.dart Loading commit data...
semantics.dart Loading commit data...
services.dart Loading commit data...
widgets.dart Loading commit data...