Было бы полезно, если бы вы упаковали эту часть кода и сделали ее виджетом, чтобы ваше дерево было чище. Вот как это делается в этом примере .
class TextFieldOverride extends StatelessWidget {
const TextFieldOverride({this.child});
final Widget child;
@override
Widget build(BuildContext context) {
final themeData = Theme.of(context);
return Theme(
child: child,
data: themeData.copyWith(
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder()),
textTheme: themeData.textTheme.copyWith(
subhead: themeData.textTheme.subhead.copyWith(
fontSize: 30.0))));
}
}
...
TextFieldOverride(
child: TextField(...)
)
Или, если в нескольких местах код будет продублирован, вы можете просто внести изменения напрямую:
...
child: TextField(
style: Theme.of(context).textTheme.subhead.copyWith(fontSize: 30.0),
decoration: InputDecoration(border: OutlineInputBorder(),
...
)
)
Или, возможно, лучший выбор - создать функцию, которая будет выполнять все вышеперечисленное.
TextField buildTextField(BuildContext context) => TextField(
style: Theme.of(context).textTheme.subhead.copyWith(fontSize: 30.0),
decoration: InputDecoration(border: OutlineInputBorder(),
...
)
)