mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Migrates the samples to remove references to the deprecated `ButtonStyleButton.iconAlignment`. The sample doesn't actually use `ButtonStyleButton.iconAlignment` directly, but it does refer to it in docs. Addresses: https://github.com/flutter/flutter/issues/179149 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
147 lines
5.2 KiB
Dart
147 lines
5.2 KiB
Dart
// 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 the [IconAlignment] property on various Material
|
|
/// button widgets.
|
|
|
|
void main() {
|
|
runApp(const IconAlignmentApp());
|
|
}
|
|
|
|
class IconAlignmentApp extends StatelessWidget {
|
|
const IconAlignmentApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const MaterialApp(home: Scaffold(body: IconAlignmentExample()));
|
|
}
|
|
}
|
|
|
|
class IconAlignmentExample extends StatefulWidget {
|
|
const IconAlignmentExample({super.key});
|
|
|
|
@override
|
|
State<IconAlignmentExample> createState() => _IconAlignmentExampleState();
|
|
}
|
|
|
|
class _IconAlignmentExampleState extends State<IconAlignmentExample> {
|
|
TextDirection _textDirection = TextDirection.ltr;
|
|
IconAlignment _iconAlignment = IconAlignment.start;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SafeArea(
|
|
child: Directionality(
|
|
key: const Key('Directionality'),
|
|
textDirection: _textDirection,
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
const Spacer(),
|
|
OverflowBar(
|
|
spacing: 10,
|
|
overflowSpacing: 20,
|
|
alignment: MainAxisAlignment.center,
|
|
overflowAlignment: OverflowBarAlignment.center,
|
|
children: <Widget>[
|
|
ElevatedButton.icon(
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.sunny),
|
|
label: const Text('ElevatedButton'),
|
|
iconAlignment: _iconAlignment,
|
|
),
|
|
FilledButton.icon(
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.beach_access),
|
|
label: const Text('FilledButton'),
|
|
iconAlignment: _iconAlignment,
|
|
),
|
|
FilledButton.tonalIcon(
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.cloud),
|
|
label: const Text('FilledButton Tonal'),
|
|
iconAlignment: _iconAlignment,
|
|
),
|
|
OutlinedButton.icon(
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.light),
|
|
label: const Text('OutlinedButton'),
|
|
iconAlignment: _iconAlignment,
|
|
),
|
|
TextButton.icon(
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.flight_takeoff),
|
|
label: const Text('TextButton'),
|
|
iconAlignment: _iconAlignment,
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
OverflowBar(
|
|
alignment: MainAxisAlignment.spaceEvenly,
|
|
overflowAlignment: OverflowBarAlignment.center,
|
|
spacing: 10,
|
|
overflowSpacing: 10,
|
|
children: <Widget>[
|
|
Column(
|
|
children: <Widget>[
|
|
const Text('Icon alignment'),
|
|
const SizedBox(height: 10),
|
|
SegmentedButton<IconAlignment>(
|
|
onSelectionChanged: (Set<IconAlignment> value) {
|
|
setState(() {
|
|
_iconAlignment = value.first;
|
|
});
|
|
},
|
|
selected: <IconAlignment>{_iconAlignment},
|
|
segments: IconAlignment.values.map((
|
|
IconAlignment iconAlignment,
|
|
) {
|
|
return ButtonSegment<IconAlignment>(
|
|
value: iconAlignment,
|
|
label: Text(iconAlignment.name),
|
|
);
|
|
}).toList(),
|
|
),
|
|
],
|
|
),
|
|
Column(
|
|
children: <Widget>[
|
|
const Text('Text direction'),
|
|
const SizedBox(height: 10),
|
|
SegmentedButton<TextDirection>(
|
|
onSelectionChanged: (Set<TextDirection> value) {
|
|
setState(() {
|
|
_textDirection = value.first;
|
|
});
|
|
},
|
|
selected: <TextDirection>{_textDirection},
|
|
segments: const <ButtonSegment<TextDirection>>[
|
|
ButtonSegment<TextDirection>(
|
|
value: TextDirection.ltr,
|
|
label: Text('LTR'),
|
|
),
|
|
ButtonSegment<TextDirection>(
|
|
value: TextDirection.rtl,
|
|
label: Text('RTL'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|