Commit 5881b13
authored
Fix DropdownButtonFormField overlay colors management (flutter#159472)
## Description
This PR fixes some `DropdownButtonFormField` issues where the overlay
color overflows.
Before this PR, `DropdownButtonFormField` was relying on an `InkWell` to
display overlay colors. This resulted in several issues related to the
`InkWell` overflowing because it is not aware of the inner container
inside `InputDecorator`, for instance see
flutter#106659.
With this PR, `DropdownButtonFormField` does not use an `InkWell` but
rely on `InputDecorator` to paint overlay colors. `InputDecorator`
paints overlay colors only on its internal container, this fixes the
color overflowing when using `InkWell`. With this change users can
opt-in for overlay colors to be painted by setting InputDecorator.filled
to true (similarly to TextField and accordingly to [the Material
specification](https://m2.material.io/components/menus#dropdown-menu)).
Code sample from flutter#106659 with
InputDecoration.filled set to true:
<details><summary>Code sample with InputDecoration.filled set to
true</summary>
```dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
final _formKey = GlobalKey<FormState>();
@OverRide
Widget build(BuildContext context) {
var items = [
'Ayo',
'This',
'Don',
'Look',
'Right',
].map((String val) {
return DropdownMenuItem(
value: val,
child: Text(
val,
),
);
}).toList();
return MaterialApp(
title: _title,
theme: ThemeData(
inputDecorationTheme: const InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32)),
borderSide: BorderSide(color: Colors.blue, width: 2),
),
),
),
home: Scaffold(
body: Center(
child: SizedBox(
width: 500,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Form(
key: _formKey,
child: DropdownButtonFormField(
onTap: () {
_formKey.currentState!.validate();
},
validator: (String? v) => 'Required',
onChanged: (String? value) {},
items: items,
// Set InputDecoration.filled to true if overlays should be visible.
// See Material specification for filled vs outlined dropdown button:
// https://m2.material.io/components/menus#dropdown-menu.
decoration: const InputDecoration(filled: true),
),
),
],
),
),
),
),
);
}
}
```
</details>
Before:

After:

After (when filled is not set to true):

## Related Issue
Fixes [DropdownButtonFormField InkWell spreads to error
message](flutter#106659).
Fixes [DropdownButtonFormField input decorator focus/hover is not
clipped and appears behind fill
color.](flutter#147069)
First step for [DropDownButtonFormField hoverColor has no effect in web
and desktop platforms](flutter#151460)
## Tests
Adds 4 tests.
Updates 2 tests (remove checks specific to InkWell usage and use filled:
true when checking for hover/focus colors).
Removes 1 test (test specific to InkWell usage, because this PR removes
the InkWell the test is obsolete).1 parent c9477b4 commit 5881b13
File tree
4 files changed
+252
-159
lines changed- packages/flutter
- lib/src/material
- test/material
4 files changed
+252
-159
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
1010 | 1009 | | |
1011 | 1010 | | |
1012 | 1011 | | |
1013 | | - | |
1014 | | - | |
| 1012 | + | |
1015 | 1013 | | |
1016 | 1014 | | |
1017 | 1015 | | |
| |||
1044 | 1042 | | |
1045 | 1043 | | |
1046 | 1044 | | |
1047 | | - | |
1048 | 1045 | | |
1049 | 1046 | | |
1050 | 1047 | | |
| |||
1056 | 1053 | | |
1057 | 1054 | | |
1058 | 1055 | | |
1059 | | - | |
1060 | | - | |
| 1056 | + | |
1061 | 1057 | | |
1062 | 1058 | | |
1063 | 1059 | | |
| |||
1287 | 1283 | | |
1288 | 1284 | | |
1289 | 1285 | | |
1290 | | - | |
1291 | | - | |
1292 | 1286 | | |
1293 | 1287 | | |
1294 | 1288 | | |
| |||
1300 | 1294 | | |
1301 | 1295 | | |
1302 | 1296 | | |
| 1297 | + | |
| 1298 | + | |
1303 | 1299 | | |
1304 | 1300 | | |
1305 | 1301 | | |
| |||
1321 | 1317 | | |
1322 | 1318 | | |
1323 | 1319 | | |
| 1320 | + | |
1324 | 1321 | | |
1325 | 1322 | | |
1326 | 1323 | | |
1327 | 1324 | | |
1328 | 1325 | | |
1329 | 1326 | | |
| 1327 | + | |
1330 | 1328 | | |
1331 | 1329 | | |
1332 | 1330 | | |
1333 | 1331 | | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
1334 | 1340 | | |
1335 | 1341 | | |
1336 | 1342 | | |
| |||
1586 | 1592 | | |
1587 | 1593 | | |
1588 | 1594 | | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
1589 | 1603 | | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
1594 | | - | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
1595 | 1656 | | |
1596 | 1657 | | |
| 1658 | + | |
1597 | 1659 | | |
1598 | 1660 | | |
1599 | 1661 | | |
1600 | 1662 | | |
1601 | 1663 | | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
1605 | | - | |
1606 | | - | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
1610 | | - | |
1611 | | - | |
1612 | | - | |
| 1664 | + | |
1613 | 1665 | | |
1614 | 1666 | | |
1615 | 1667 | | |
| |||
1679 | 1731 | | |
1680 | 1732 | | |
1681 | 1733 | | |
1682 | | - | |
| 1734 | + | |
1683 | 1735 | | |
1684 | 1736 | | |
1685 | 1737 | | |
1686 | 1738 | | |
1687 | 1739 | | |
1688 | | - | |
| 1740 | + | |
1689 | 1741 | | |
1690 | 1742 | | |
1691 | 1743 | | |
| |||
1707 | 1759 | | |
1708 | 1760 | | |
1709 | 1761 | | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | 1762 | | |
1724 | 1763 | | |
1725 | 1764 | | |
| |||
1745 | 1784 | | |
1746 | 1785 | | |
1747 | 1786 | | |
1748 | | - | |
1749 | | - | |
1750 | | - | |
1751 | | - | |
1752 | | - | |
| 1787 | + | |
1753 | 1788 | | |
1754 | 1789 | | |
1755 | 1790 | | |
1756 | 1791 | | |
1757 | 1792 | | |
1758 | 1793 | | |
1759 | | - | |
1760 | 1794 | | |
1761 | 1795 | | |
1762 | 1796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2079 | 2079 | | |
2080 | 2080 | | |
2081 | 2081 | | |
2082 | | - | |
2083 | 2082 | | |
2084 | 2083 | | |
2085 | 2084 | | |
| |||
Lines changed: 37 additions & 98 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
1130 | 1129 | | |
1131 | 1130 | | |
1132 | 1131 | | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
1148 | | - | |
1149 | | - | |
1150 | | - | |
1151 | | - | |
1152 | | - | |
1153 | | - | |
1154 | | - | |
1155 | | - | |
1156 | | - | |
1157 | | - | |
1158 | | - | |
1159 | | - | |
1160 | | - | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
1170 | | - | |
1171 | | - | |
1172 | | - | |
1173 | | - | |
1174 | | - | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
1182 | | - | |
1183 | | - | |
1184 | | - | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
1206 | | - | |
1207 | | - | |
1208 | | - | |
1209 | | - | |
1210 | | - | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
1214 | | - | |
1215 | | - | |
1216 | | - | |
1217 | | - | |
1218 | | - | |
1219 | | - | |
1220 | | - | |
1221 | | - | |
1222 | | - | |
1223 | | - | |
1224 | | - | |
1225 | | - | |
1226 | | - | |
1227 | | - | |
1228 | | - | |
1229 | | - | |
1230 | 1132 | | |
1231 | 1133 | | |
1232 | 1134 | | |
| |||
1307 | 1209 | | |
1308 | 1210 | | |
1309 | 1211 | | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
1310 | 1249 | | |
0 commit comments