@@ -5,21 +5,36 @@ import 'package:flutter/material.dart';
55
66class MaterialBindingStyle extends BindingStyleExtension <MaterialBindingStyle >
77 implements StructureMetadata , BindingStyleModifier {
8- final InputDecorationTheme ? inputTheme;
8+ final InputDecorationThemeData ? inputTheme;
9+ final InputDecorationThemeData ? sectionTheme;
910 final ButtonStyle ? buttonStyle;
1011
11- const MaterialBindingStyle ({this .inputTheme, this .buttonStyle});
12+ const MaterialBindingStyle ({
13+ this .inputTheme,
14+ this .buttonStyle,
15+ this .sectionTheme,
16+ });
1217
13- const MaterialBindingStyle .inputTheme (this .inputTheme) : buttonStyle = null ;
18+ const MaterialBindingStyle .inputTheme (this .inputTheme)
19+ : buttonStyle = null ,
20+ sectionTheme = null ;
1421
15- const MaterialBindingStyle .buttonStyle (this .buttonStyle) : inputTheme = null ;
22+ const MaterialBindingStyle .buttonStyle (this .buttonStyle)
23+ : inputTheme = null ,
24+ sectionTheme = null ;
25+
26+ const MaterialBindingStyle .sectionTheme (this .sectionTheme)
27+ : inputTheme = null ,
28+ buttonStyle = null ;
1629
1730 @override
1831 MaterialBindingStyle merge (MaterialBindingStyle ? other) {
1932 if (other == null ) return this ;
2033 return MaterialBindingStyle (
2134 inputTheme: inputTheme? .merge (other.inputTheme) ?? other.inputTheme,
2235 buttonStyle: buttonStyle? .merge (other.buttonStyle) ?? other.buttonStyle,
36+ sectionTheme:
37+ sectionTheme? .merge (other.sectionTheme) ?? other.sectionTheme,
2338 );
2439 }
2540
@@ -35,14 +50,7 @@ extension BindingStyleDataMaterialExtension on BindingStyle {
3550 bool includeHelper = true ,
3651 bool includeHint = true ,
3752 }) {
38- final currentTheme = Theme .of (context);
39- final theme =
40- getExtension <MaterialBindingStyle >() ?? MaterialBindingStyle ();
41- final inputTheme =
42- theme.inputTheme? .merge (
43- InputDecorationTheme (data: currentTheme.inputDecorationTheme),
44- ) ??
45- currentTheme.inputDecorationTheme;
53+ var (inputTheme, style, theme) = resolveTheme (context);
4654 final decoration = InputDecoration ()
4755 .applyDefaults (inputTheme)
4856 .copyWith (
@@ -61,17 +69,25 @@ extension BindingStyleDataMaterialExtension on BindingStyle {
6169 Object ? labelOverride = #none,
6270 String ? errorText,
6371 }) {
64- return Padding (
65- padding: const EdgeInsets .symmetric (vertical: 8.0 ),
66- child: InputDecorator (
67- decoration: InputDecoration (
68- border: OutlineInputBorder (),
72+ var (inputTheme, style, theme) = resolveTheme (context);
73+ if (style.sectionTheme != null ) {
74+ inputTheme = style.sectionTheme! .merge (inputTheme);
75+ } else {
76+ inputTheme = inputTheme.copyWith (border: OutlineInputBorder ());
77+ }
78+ var decoration = InputDecoration ()
79+ .applyDefaults (inputTheme)
80+ .copyWith (
6981 labelText: labelOverride == #none ? label : labelOverride.toString (),
7082 errorText: errorText,
71- helperText: helper
72- ),
73- child: widget,
74- ),
83+ helperText: helper,
84+ prefix: prefix,
85+ suffix: suffix,
86+ );
87+
88+ return Padding (
89+ padding: const EdgeInsets .symmetric (vertical: 8.0 ),
90+ child: InputDecorator (decoration: decoration, child: widget),
7591 );
7692 }
7793
@@ -86,22 +102,12 @@ extension BindingStyleDataMaterialExtension on BindingStyle {
86102 }
87103
88104 if (label == null ) return null ;
89- final currentTheme = Theme .of (context);
90- final theme =
91- getExtension <MaterialBindingStyle >() ?? MaterialBindingStyle ();
92- final inputTheme =
93- theme.inputTheme? .merge (
94- InputDecorationTheme (data: currentTheme.inputDecorationTheme),
95- ) ??
96- InputDecorationTheme (data: currentTheme.inputDecorationTheme);
105+ final (inputTheme, bindingStyle, theme) = resolveTheme (context);
97106 var style = inputTheme.labelStyle;
98-
99107 if (isError) {
100108 style =
101- inputTheme.errorStyle ??
102- TextStyle (color: currentTheme.colorScheme.error);
109+ inputTheme.errorStyle ?? TextStyle (color: theme.colorScheme.error);
103110 }
104-
105111 return Text (label, style: style);
106112 }
107113
@@ -114,37 +120,33 @@ extension BindingStyleDataMaterialExtension on BindingStyle {
114120
115121 Widget ? buildMaterialHelperText (BuildContext context) {
116122 if (helper == null ) return null ;
117- final currentTheme = Theme .of (context);
118- final theme =
119- getExtension <MaterialBindingStyle >() ?? MaterialBindingStyle ();
120- final inputTheme =
121- theme.inputTheme? .merge (
122- InputDecorationTheme (data: currentTheme.inputDecorationTheme),
123- ) ??
124- InputDecorationTheme (data: currentTheme.inputDecorationTheme);
123+ final (inputTheme, style, theme) = resolveTheme (context);
125124 return Text (helper! , style: inputTheme.helperStyle);
126125 }
127126
128127 Widget ? buildMaterialErrorText (BuildContext context, String ? error) {
129128 if (error == null ) return null ;
130- final currentTheme = Theme .of (context);
131- final theme =
132- getExtension <MaterialBindingStyle >() ?? MaterialBindingStyle ();
133- final inputTheme =
134- theme.inputTheme? .merge (
135- InputDecorationTheme (data: currentTheme.inputDecorationTheme),
136- ) ??
137- InputDecorationTheme (data: currentTheme.inputDecorationTheme);
138-
129+ final (inputTheme, style, theme) = resolveTheme (context);
139130 return DefaultTextStyle (
140- style:
141- inputTheme.errorStyle ??
142- TextStyle (color: currentTheme.colorScheme.error),
131+ style: inputTheme.errorStyle ?? TextStyle (color: theme.colorScheme.error),
143132 child: Text (error),
144133 );
145134 }
146135
147136 ButtonStyle ? getMaterialButtonStyle () {
148137 return getExtension <MaterialBindingStyle >()? .buttonStyle;
149138 }
139+
140+ (InputDecorationThemeData , MaterialBindingStyle , ThemeData ) resolveTheme (
141+ BuildContext context,
142+ ) {
143+ final currentTheme = Theme .of (context);
144+ final style =
145+ getExtension <MaterialBindingStyle >() ?? MaterialBindingStyle ();
146+ var inputTheme = currentTheme.inputDecorationTheme;
147+ if (style.inputTheme != null ) {
148+ inputTheme = style.inputTheme! .merge (inputTheme);
149+ }
150+ return (inputTheme, style, currentTheme);
151+ }
150152}
0 commit comments