Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
1c374c65
Unverified
Commit
1c374c65
authored
Oct 06, 2021
by
Bjarte Bore
Committed by
GitHub
Oct 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for MaterialState to InputDecorator (#91182)
parent
ed601036
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
666 additions
and
52 deletions
+666
-52
input_decoration.material_state.0.dart
...al/input_decorator/input_decoration.material_state.0.dart
+48
-0
input_decoration.material_state.1.dart
...al/input_decorator/input_decoration.material_state.1.dart
+55
-0
input_decorator.dart
packages/flutter/lib/src/material/input_decorator.dart
+264
-47
material_state.dart
packages/flutter/lib/src/material/material_state.dart
+195
-5
input_decorator_test.dart
packages/flutter/test/material/input_decorator_test.dart
+104
-0
No files found.
examples/api/lib/material/input_decorator/input_decoration.material_state.0.dart
0 → 100644
View file @
1c374c65
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for InputDecoration
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
MyApp
());
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
static
const
String
_title
=
'Flutter Code Sample'
;
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
_title
,
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
_title
)),
body:
const
MyStatelessWidget
(),
),
);
}
}
class
MyStatelessWidget
extends
StatelessWidget
{
const
MyStatelessWidget
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
return
TextFormField
(
initialValue:
'abc'
,
decoration:
InputDecoration
(
prefixIcon:
const
Icon
(
Icons
.
person
),
prefixIconColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
focused
))
{
return
Colors
.
green
;
}
if
(
states
.
contains
(
MaterialState
.
error
))
{
return
Colors
.
red
;
}
return
Colors
.
grey
;
}),
),
);
}
}
examples/api/lib/material/input_decorator/input_decoration.material_state.1.dart
0 → 100644
View file @
1c374c65
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for InputDecoration
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
MyApp
());
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
static
const
String
_title
=
'Flutter Code Sample'
;
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
_title
,
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
_title
)),
body:
const
MyStatelessWidget
(),
),
);
}
}
class
MyStatelessWidget
extends
StatelessWidget
{
const
MyStatelessWidget
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
final
ThemeData
themeData
=
Theme
.
of
(
context
);
return
Theme
(
data:
themeData
.
copyWith
(
inputDecorationTheme:
themeData
.
inputDecorationTheme
.
copyWith
(
prefixIconColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
focused
))
{
return
Colors
.
green
;
}
if
(
states
.
contains
(
MaterialState
.
error
))
{
return
Colors
.
red
;
}
return
Colors
.
grey
;
}),
)
),
child:
TextFormField
(
initialValue:
'abc'
,
decoration:
const
InputDecoration
(
prefixIcon:
Icon
(
Icons
.
person
),
),
),
);
}
}
packages/flutter/lib/src/material/input_decorator.dart
View file @
1c374c65
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/material/material_state.dart
View file @
1c374c65
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/input_decorator_test.dart
View file @
1c374c65
...
@@ -3664,6 +3664,110 @@ void main() {
...
@@ -3664,6 +3664,110 @@ void main() {
expect
(
decoration
.
constraints
,
const
BoxConstraints
(
minWidth:
10
,
maxWidth:
20
,
minHeight:
30
,
maxHeight:
40
));
expect
(
decoration
.
constraints
,
const
BoxConstraints
(
minWidth:
10
,
maxWidth:
20
,
minHeight:
30
,
maxHeight:
40
));
});
});
testWidgets
(
'InputDecorationTheme.inputDecoration with MaterialState'
,
(
WidgetTester
tester
)
async
{
final
MaterialStateTextStyle
themeStyle
=
MaterialStateTextStyle
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
const
TextStyle
(
color:
Colors
.
green
);
});
final
MaterialStateTextStyle
decorationStyle
=
MaterialStateTextStyle
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
const
TextStyle
(
color:
Colors
.
blue
);
});
// InputDecorationTheme arguments define InputDecoration properties.
InputDecoration
decoration
=
const
InputDecoration
().
applyDefaults
(
InputDecorationTheme
(
labelStyle:
themeStyle
,
helperStyle:
themeStyle
,
hintStyle:
themeStyle
,
errorStyle:
themeStyle
,
isDense:
true
,
contentPadding:
const
EdgeInsets
.
all
(
1.0
),
prefixStyle:
themeStyle
,
suffixStyle:
themeStyle
,
counterStyle:
themeStyle
,
filled:
true
,
fillColor:
Colors
.
red
,
focusColor:
Colors
.
blue
,
border:
InputBorder
.
none
,
alignLabelWithHint:
true
,
constraints:
const
BoxConstraints
(
minWidth:
10
,
maxWidth:
20
,
minHeight:
30
,
maxHeight:
40
),
),
);
expect
(
decoration
.
labelStyle
,
themeStyle
);
expect
(
decoration
.
helperStyle
,
themeStyle
);
expect
(
decoration
.
hintStyle
,
themeStyle
);
expect
(
decoration
.
errorStyle
,
themeStyle
);
expect
(
decoration
.
isDense
,
true
);
expect
(
decoration
.
contentPadding
,
const
EdgeInsets
.
all
(
1.0
));
expect
(
decoration
.
prefixStyle
,
themeStyle
);
expect
(
decoration
.
suffixStyle
,
themeStyle
);
expect
(
decoration
.
counterStyle
,
themeStyle
);
expect
(
decoration
.
filled
,
true
);
expect
(
decoration
.
fillColor
,
Colors
.
red
);
expect
(
decoration
.
border
,
InputBorder
.
none
);
expect
(
decoration
.
alignLabelWithHint
,
true
);
expect
(
decoration
.
constraints
,
const
BoxConstraints
(
minWidth:
10
,
maxWidth:
20
,
minHeight:
30
,
maxHeight:
40
));
// InputDecoration (baseDecoration) defines InputDecoration properties
final
MaterialStateOutlineInputBorder
border
=
MaterialStateOutlineInputBorder
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
const
OutlineInputBorder
();
});
decoration
=
InputDecoration
(
labelStyle:
decorationStyle
,
helperStyle:
decorationStyle
,
hintStyle:
decorationStyle
,
errorStyle:
decorationStyle
,
isDense:
false
,
contentPadding:
const
EdgeInsets
.
all
(
4.0
),
prefixStyle:
decorationStyle
,
suffixStyle:
decorationStyle
,
counterStyle:
decorationStyle
,
filled:
false
,
fillColor:
Colors
.
blue
,
border:
border
,
alignLabelWithHint:
false
,
constraints:
const
BoxConstraints
(
minWidth:
10
,
maxWidth:
20
,
minHeight:
30
,
maxHeight:
40
),
).
applyDefaults
(
InputDecorationTheme
(
labelStyle:
themeStyle
,
helperStyle:
themeStyle
,
helperMaxLines:
5
,
hintStyle:
themeStyle
,
errorStyle:
themeStyle
,
errorMaxLines:
4
,
isDense:
true
,
contentPadding:
const
EdgeInsets
.
all
(
1.0
),
prefixStyle:
themeStyle
,
suffixStyle:
themeStyle
,
counterStyle:
themeStyle
,
filled:
true
,
fillColor:
Colors
.
red
,
focusColor:
Colors
.
blue
,
border:
InputBorder
.
none
,
alignLabelWithHint:
true
,
constraints:
const
BoxConstraints
(
minWidth:
40
,
maxWidth:
30
,
minHeight:
20
,
maxHeight:
10
),
),
);
expect
(
decoration
.
labelStyle
,
decorationStyle
);
expect
(
decoration
.
helperStyle
,
decorationStyle
);
expect
(
decoration
.
helperMaxLines
,
5
);
expect
(
decoration
.
hintStyle
,
decorationStyle
);
expect
(
decoration
.
errorStyle
,
decorationStyle
);
expect
(
decoration
.
errorMaxLines
,
4
);
expect
(
decoration
.
isDense
,
false
);
expect
(
decoration
.
contentPadding
,
const
EdgeInsets
.
all
(
4.0
));
expect
(
decoration
.
prefixStyle
,
decorationStyle
);
expect
(
decoration
.
suffixStyle
,
decorationStyle
);
expect
(
decoration
.
counterStyle
,
decorationStyle
);
expect
(
decoration
.
filled
,
false
);
expect
(
decoration
.
fillColor
,
Colors
.
blue
);
expect
(
decoration
.
border
,
isA
<
MaterialStateOutlineInputBorder
>());
expect
(
decoration
.
alignLabelWithHint
,
false
);
expect
(
decoration
.
constraints
,
const
BoxConstraints
(
minWidth:
10
,
maxWidth:
20
,
minHeight:
30
,
maxHeight:
40
));
});
testWidgets
(
'InputDecorator OutlineInputBorder fillColor is clipped by border'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'InputDecorator OutlineInputBorder fillColor is clipped by border'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/15742
// This is a regression test for https://github.com/flutter/flutter/issues/15742
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment