From 13d14f1843fdf5accff096439d530b2aafa90ef3 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Wed, 27 Oct 2021 10:38:02 +0300 Subject: [PATCH] [doc] Update `suffixIcon`/`prefixIcon` for alignment with code snippet (#91998) --- .../input_decoration.prefix_icon.0.dart | 42 +++++++++++++++++++ .../input_decoration.suffix_icon.0.dart | 42 +++++++++++++++++++ .../input_decoration.prefix_icon.0_test.dart | 16 +++++++ .../input_decoration.suffix_icon.0_test.dart | 16 +++++++ .../lib/src/material/input_decorator.dart | 24 +++++++++++ 5 files changed, 140 insertions(+) create mode 100644 examples/api/lib/material/input_decorator/input_decoration.prefix_icon.0.dart create mode 100644 examples/api/lib/material/input_decorator/input_decoration.suffix_icon.0.dart create mode 100644 examples/api/test/material/input_decorator/input_decoration.prefix_icon.0_test.dart create mode 100644 examples/api/test/material/input_decorator/input_decoration.suffix_icon.0_test.dart diff --git a/examples/api/lib/material/input_decorator/input_decoration.prefix_icon.0.dart b/examples/api/lib/material/input_decorator/input_decoration.prefix_icon.0.dart new file mode 100644 index 0000000000..b3750661e3 --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.prefix_icon.0.dart @@ -0,0 +1,42 @@ +// 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 InputDecorator + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: 'Input Decorator Sample', + home: Scaffold(body: InputDecoratorExample()), + ); + } +} + +class InputDecoratorExample extends StatelessWidget { + const InputDecoratorExample({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const TextField( + decoration: InputDecoration( + border: OutlineInputBorder(), + labelText: 'Enter name', + prefixIcon: Align( + widthFactor: 1.0, + heightFactor: 1.0, + child: Icon( + Icons.person, + ), + ), + ), + ); + } +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.suffix_icon.0.dart b/examples/api/lib/material/input_decorator/input_decoration.suffix_icon.0.dart new file mode 100644 index 0000000000..0ae5f2f08f --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.suffix_icon.0.dart @@ -0,0 +1,42 @@ +// 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 InputDecorator + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: 'Input Decorator Sample', + home: Scaffold(body: InputDecoratorExample()), + ); + } +} + +class InputDecoratorExample extends StatelessWidget { + const InputDecoratorExample({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const TextField( + decoration: InputDecoration( + border: OutlineInputBorder(), + labelText: 'Enter password', + suffixIcon: Align( + widthFactor: 1.0, + heightFactor: 1.0, + child: Icon( + Icons.remove_red_eye, + ), + ), + ), + ); + } +} diff --git a/examples/api/test/material/input_decorator/input_decoration.prefix_icon.0_test.dart b/examples/api/test/material/input_decorator/input_decoration.prefix_icon.0_test.dart new file mode 100644 index 0000000000..aeb791da4e --- /dev/null +++ b/examples/api/test/material/input_decorator/input_decoration.prefix_icon.0_test.dart @@ -0,0 +1,16 @@ +// 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.prefix_icon.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('InputDecorator prefixIcon alignment', (WidgetTester tester) async { + await tester.pumpWidget( + const example.MyApp(), + ); + expect(tester.getCenter(find.byIcon(Icons.person)).dy, 28.0); + }); +} diff --git a/examples/api/test/material/input_decorator/input_decoration.suffix_icon.0_test.dart b/examples/api/test/material/input_decorator/input_decoration.suffix_icon.0_test.dart new file mode 100644 index 0000000000..15d8a9069c --- /dev/null +++ b/examples/api/test/material/input_decorator/input_decoration.suffix_icon.0_test.dart @@ -0,0 +1,16 @@ +// 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.suffix_icon.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('InputDecorator suffixIcon alignment', (WidgetTester tester) async { + await tester.pumpWidget( + const example.MyApp(), + ); + expect(tester.getCenter(find.byIcon(Icons.remove_red_eye)).dy, 28.0); + }); +} diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 67fd790292..d9961aed4f 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2945,12 +2945,24 @@ class InputDecoration { /// [icon] and above the widgets that contain [helperText], /// [errorText], and [counterText]. /// + /// The prefix icon aligment can be changed using [Align] with a fixed `widthFactor` and + /// `heightFactor`. + /// + /// {@tool dartpad} + /// This example shows how the prefix icon alignment can be changed using [Align] with + /// a fixed `widthFactor` and `heightFactor`. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.prefix_icon.0.dart ** + /// {@end-tool} + /// /// See also: /// /// * [Icon] and [ImageIcon], which are typically used to show icons. /// * [prefix] and [prefixText], which are other ways to show content /// before the text field (but after the icon). /// * [suffixIcon], which is the same but on the trailing edge. + /// * [Align] A widget that aligns its child within itself and optionally + /// sizes itself based on the child's size. final Widget? prefixIcon; /// The constraints for the prefix icon. @@ -3055,12 +3067,24 @@ class InputDecoration { /// [icon] and above the widgets that contain [helperText], /// [errorText], and [counterText]. /// + /// The suffix icon aligment can be changed using [Align] with a fixed `widthFactor` and + /// `heightFactor`. + /// + /// {@tool dartpad} + /// This example shows how the suffix icon alignment can be changed using [Align] with + /// a fixed `widthFactor` and `heightFactor`. + /// + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.suffix_icon.0.dart ** + /// {@end-tool} + /// /// See also: /// /// * [Icon] and [ImageIcon], which are typically used to show icons. /// * [suffix] and [suffixText], which are other ways to show content /// after the text field (but before the icon). /// * [prefixIcon], which is the same but on the leading edge. + /// * [Align] A widget that aligns its child within itself and optionally + /// sizes itself based on the child's size. final Widget? suffixIcon; /// Optional widget to place on the line after the input.