Add helper widget parameter to InputDecoration (#145157)
This pull request introduces a new field named `helper` to the InputDecoration class. This field allows for specifying a widget containing contextual information about the InputDecorator.child's value. Unlike `helperText`, which accepts a plain string, `helper` supports widgets, enabling functionalities like tappable links for further explanation. This change aligns with the established pattern of `error`, `label`, `prefix`, and `suffix`. fixes [#145163](https://github.com/flutter/flutter/issues/145163)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Flutter code sample for [InputDecoration.helper].
|
||||
|
||||
void main() => runApp(const HelperExampleApp());
|
||||
|
||||
class HelperExampleApp extends StatelessWidget {
|
||||
const HelperExampleApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('InputDecoration.helper Sample')),
|
||||
body: const HelperExample(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HelperExample extends StatelessWidget {
|
||||
const HelperExample({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
helper: Text.rich(
|
||||
TextSpan(
|
||||
children: <InlineSpan>[
|
||||
WidgetSpan(
|
||||
child: Text(
|
||||
'Helper Text ',
|
||||
),
|
||||
),
|
||||
WidgetSpan(
|
||||
child: Icon(
|
||||
Icons.help_outline,
|
||||
color: Colors.blue,
|
||||
size: 20.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/input_decorator/input_decoration.helper.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('InputDecorator helper', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.HelperExampleApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
expect(find.text('Helper Text '), findsOneWidget);
|
||||
expect(find.byIcon(Icons.help_outline), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user