flutter/examples/api/lib/material/action_buttons/action_icon_theme.0.dart
Mushaheed Syed 7d85a585da
Add ActionButtonIconsData for overriding action icons (#118229)
* Add ActionButtonIconsData for overriding action icons

* Fix formatting issues

* Add missing exports in material library and add copyWith method in ActionButtonIconsData

* Move all action buttons, and icons to action_buttons.dart

* Rename actionButtonIcons to actionIconTheme

* Refactor buttons in action_buttons.dart to extend a private class for common implementation

* Refactor icons in action_buttons

* Fix docs in action_buttons_theme

* Fix #107646 always use 'Icons.arrow_back' as a back_button icon in web

* Update documentation for action buttons and add style parameter to every action button

* Fix analyzer warnings

* Add missing style argument in IconButton of _ActionButton

* Add tests for action buttons, action icon theme, drawer buttons, and back buttons

* Add example (+test) for action icon button's action icon theme in examples/api

* Fix analysis errors

* Add missing license header in action_icon_theme.0.dart

* Fix deprecation notice in theme_data.dart

* Update theme data tests for actionIconTheme

* Remove iconSize parameter from ActionButtons and update docs

* Fix failing tests

* Update button color during backbutton tests to red

* Fix analytics issues

* Fix format
2023-02-22 09:22:44 -08:00

117 lines
2.8 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.
// Flutter code sample for [ActionIconTheme].
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class _CustomEndDrawerIcon extends StatelessWidget {
const _CustomEndDrawerIcon();
@override
Widget build(BuildContext context) {
final MaterialLocalizations localization = MaterialLocalizations.of(context);
return Icon(
Icons.more_horiz,
semanticLabel: localization.openAppDrawerTooltip,
);
}
}
class _CustomDrawerIcon extends StatelessWidget {
const _CustomDrawerIcon();
@override
Widget build(BuildContext context) {
final MaterialLocalizations localization = MaterialLocalizations.of(context);
return Icon(
Icons.segment,
semanticLabel: localization.openAppDrawerTooltip,
);
}
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
useMaterial3: true,
actionIconTheme: ActionIconThemeData(
backButtonIconBuilder: (BuildContext context) {
return const Icon(Icons.arrow_back_ios_new_rounded);
},
drawerButtonIconBuilder: (BuildContext context) {
return const _CustomDrawerIcon();
},
endDrawerButtonIconBuilder: (BuildContext context) {
return const _CustomEndDrawerIcon();
},
),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
drawer: const Drawer(),
body: const Center(
child: NextPageButton(),
),
);
}
}
class NextPageButton extends StatelessWidget {
const NextPageButton({super.key});
@override
Widget build(BuildContext context) {
return ElevatedButton.icon(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<MySecondPage>(builder: (BuildContext context) {
return const MySecondPage();
}),
);
},
icon: const Icon(Icons.arrow_forward),
label: const Text('Next page'),
);
}
}
class MySecondPage extends StatelessWidget {
const MySecondPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second page'),
),
endDrawer: const Drawer(),
);
}
}