Skip to content

Instantly share code, notes, and snippets.

@esouthren
Created January 3, 2023 18:38
Show Gist options
  • Save esouthren/d9b90b67d6bc18b09b9309c09080355a to your computer and use it in GitHub Desktop.
Save esouthren/d9b90b67d6bc18b09b9309c09080355a to your computer and use it in GitHub Desktop.
AppBar icon override
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = ThemeData.light(useMaterial3: true);
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
appBarTheme: theme.appBarTheme.copyWith(
// EXPECTED: We expect to see these values for our icon color.
actionsIconTheme: const IconThemeData(
color: Colors.red,
),
iconTheme: const IconThemeData(
color: Colors.blue,
),
),
// ACTUAL: Instead, we see this value (try commenting this parameter out):
iconButtonTheme: IconButtonThemeData(
style: IconButton.styleFrom(
foregroundColor: Colors.yellow,
),
),
),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
leading: appBarButton(),
actions: [appBarButton()],
title: const Text('App Bar'),
),
body: Center(
child: MyWidget(),
),
),
);
}
Widget appBarButton() => IconButton(
tooltip: 'Settings',
icon: const Icon(Icons.settings),
onPressed: () {},
);
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(50.0),
child: Text(
'Icons above should be inheriting color values from AppBarTheme.iconTheme and AppBarTheme.actionsIconTheme. However, the icons are using any IconButtonTheme override present in the theme.',
style: Theme.of(context).textTheme.bodySmall,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment