Loïc Sharma d248a651b6
Add flutter_lints to samples (#179091)
I recommend reviewing each commit individually.

The following were suppressed instead of migrated to minimize the time
the tree is closed:

1. The [`Radio` -> `RadioGroup`
migration](https://docs.flutter.dev/release/breaking-changes/radio-api-redesign).
Tracked by: https://github.com/flutter/flutter/issues/179088.

Part of: https://github.com/flutter/flutter/issues/178827

## 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
2025-11-26 22:11:20 +00:00

111 lines
3.7 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';
void main() {
runApp(const ThemeDataExampleApp());
}
// This app's theme specifies an overall ColorScheme as well as overrides
// for the default configuration of FloatingActionButtons. To customize
// the appearance of other components, add additional component specific
// themes, rather than tweaking the color scheme.
//
// Creating an entire color scheme from a single seed color is a good
// way to ensure a visually appealing color palette where the default
// component colors have sufficient contrast for accessibility. Another
// good way to create an app's color scheme is to use
// ColorScheme.fromImageProvider.
//
// The color scheme reflects the platform's light or dark setting
// which is retrieved with `MediaQuery.platformBrightnessOf`. The color
// scheme's colors will be different for light and dark settings although
// they'll all be related to the seed color in both cases.
//
// Color scheme colors have been used where component defaults have
// been overridden so that the app will look good and remain accessible
// in both light and dark modes.
//
// Text styles are derived from the theme's textTheme (not the obsolete
// primaryTextTheme property) and then customized using copyWith.
// Using the _on_ version of a color scheme color as the foreground,
// as in `tertiary` and `onTertiary`, guarantees sufficient contrast
// for readability/accessibility.
class ThemeDataExampleApp extends StatelessWidget {
const ThemeDataExampleApp({super.key});
@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = ColorScheme.fromSeed(
brightness: MediaQuery.platformBrightnessOf(context),
seedColor: Colors.indigo,
);
return MaterialApp(
title: 'ThemeData Demo',
theme: ThemeData(
colorScheme: colorScheme,
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: colorScheme.tertiary,
foregroundColor: colorScheme.onTertiary,
),
),
home: const Home(),
);
}
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
int buttonPressCount = 0;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final double pointCount = 8 + (buttonPressCount % 6);
return Scaffold(
appBar: AppBar(title: const Text('Press the + Button')),
// An AnimatedContainer makes the decoration changes entertaining.
body: AnimatedContainer(
duration: const Duration(milliseconds: 500),
margin: const EdgeInsets.all(32),
alignment: Alignment.center,
decoration: ShapeDecoration(
color: colorScheme.tertiaryContainer,
shape: StarBorder(
points: pointCount,
pointRounding: 0.4,
valleyRounding: 0.6,
side: BorderSide(width: 9, color: colorScheme.tertiary),
),
),
child: Text(
'${pointCount.toInt()} Points',
style: theme.textTheme.headlineMedium!.copyWith(
color: colorScheme.onPrimaryContainer,
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
buttonPressCount += 1;
});
},
tooltip: "Change the shape's point count",
child: const Icon(Icons.add),
),
);
}
}