mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
## Description This removes all of the comments that are of the form "so-and-so (must not be null|can ?not be null|must be non-null)" from the cases where those values are defines as non-nullable values. This PR removes them from the material library. This was done by hand, since it really didn't lend itself to scripting, so it needs to be more than just spot-checked, I think. I was careful to leave any comment that referred to parameters that were nullable, but I may have missed some. In addition to being no longer relevant after null safety has been made the default, these comments were largely fragile, in that it was easy for them to get out of date, and not be accurate anymore anyhow. This did create a number of constructor comments which basically say "Creates a [Foo].", but I don't really know how to avoid that in a large scale change, since there's not much you can really say in a lot of cases. I think we might consider some leniency for constructors to the "Comment must be meaningful" style guidance (which we de facto have already, since there are a bunch of these). ## Related PRs - https://github.com/flutter/flutter/pull/134984 - https://github.com/flutter/flutter/pull/134992 - https://github.com/flutter/flutter/pull/134993 - https://github.com/flutter/flutter/pull/134994 ## Tests - Documentation only change.
126 lines
4.2 KiB
Dart
126 lines
4.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/foundation.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'button_style.dart';
|
|
import 'theme.dart';
|
|
|
|
// Examples can assume:
|
|
// late BuildContext context;
|
|
|
|
/// A [ButtonStyle] that overrides the default appearance of
|
|
/// [TextButton]s when it's used with [TextButtonTheme] or with the
|
|
/// overall [Theme]'s [ThemeData.textButtonTheme].
|
|
///
|
|
/// The [style]'s properties override [TextButton]'s default style,
|
|
/// i.e. the [ButtonStyle] returned by [TextButton.defaultStyleOf]. Only
|
|
/// the style's non-null property values or resolved non-null
|
|
/// [MaterialStateProperty] values are used.
|
|
///
|
|
/// See also:
|
|
///
|
|
/// * [TextButtonTheme], the theme which is configured with this class.
|
|
/// * [TextButton.defaultStyleOf], which returns the default [ButtonStyle]
|
|
/// for text buttons.
|
|
/// * [TextButton.styleFrom], which converts simple values into a
|
|
/// [ButtonStyle] that's consistent with [TextButton]'s defaults.
|
|
/// * [MaterialStateProperty.resolve], "resolve" a material state property
|
|
/// to a simple value based on a set of [MaterialState]s.
|
|
/// * [ThemeData.textButtonTheme], which can be used to override the default
|
|
/// [ButtonStyle] for [TextButton]s below the overall [Theme].
|
|
@immutable
|
|
class TextButtonThemeData with Diagnosticable {
|
|
/// Creates a [TextButtonThemeData].
|
|
///
|
|
/// The [style] may be null.
|
|
const TextButtonThemeData({ this.style });
|
|
|
|
/// Overrides for [TextButton]'s default style.
|
|
///
|
|
/// Non-null properties or non-null resolved [MaterialStateProperty]
|
|
/// values override the [ButtonStyle] returned by
|
|
/// [TextButton.defaultStyleOf].
|
|
///
|
|
/// If [style] is null, then this theme doesn't override anything.
|
|
final ButtonStyle? style;
|
|
|
|
/// Linearly interpolate between two text button themes.
|
|
static TextButtonThemeData? lerp(TextButtonThemeData? a, TextButtonThemeData? b, double t) {
|
|
if (identical(a, b)) {
|
|
return a;
|
|
}
|
|
return TextButtonThemeData(
|
|
style: ButtonStyle.lerp(a?.style, b?.style, t),
|
|
);
|
|
}
|
|
|
|
@override
|
|
int get hashCode => style.hashCode;
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) {
|
|
return true;
|
|
}
|
|
if (other.runtimeType != runtimeType) {
|
|
return false;
|
|
}
|
|
return other is TextButtonThemeData && other.style == style;
|
|
}
|
|
|
|
@override
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
super.debugFillProperties(properties);
|
|
properties.add(DiagnosticsProperty<ButtonStyle>('style', style, defaultValue: null));
|
|
}
|
|
}
|
|
|
|
/// Overrides the default [ButtonStyle] of its [TextButton] descendants.
|
|
///
|
|
/// See also:
|
|
///
|
|
/// * [TextButtonThemeData], which is used to configure this theme.
|
|
/// * [TextButton.defaultStyleOf], which returns the default [ButtonStyle]
|
|
/// for text buttons.
|
|
/// * [TextButton.styleFrom], which converts simple values into a
|
|
/// [ButtonStyle] that's consistent with [TextButton]'s defaults.
|
|
/// * [ThemeData.textButtonTheme], which can be used to override the default
|
|
/// [ButtonStyle] for [TextButton]s below the overall [Theme].
|
|
class TextButtonTheme extends InheritedTheme {
|
|
/// Create a [TextButtonTheme].
|
|
const TextButtonTheme({
|
|
super.key,
|
|
required this.data,
|
|
required super.child,
|
|
});
|
|
|
|
/// The configuration of this theme.
|
|
final TextButtonThemeData data;
|
|
|
|
/// The closest instance of this class that encloses the given context.
|
|
///
|
|
/// If there is no enclosing [TextButtonTheme] widget, then
|
|
/// [ThemeData.textButtonTheme] is used.
|
|
///
|
|
/// Typical usage is as follows:
|
|
///
|
|
/// ```dart
|
|
/// TextButtonThemeData theme = TextButtonTheme.of(context);
|
|
/// ```
|
|
static TextButtonThemeData of(BuildContext context) {
|
|
final TextButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<TextButtonTheme>();
|
|
return buttonTheme?.data ?? Theme.of(context).textButtonTheme;
|
|
}
|
|
|
|
@override
|
|
Widget wrap(BuildContext context, Widget child) {
|
|
return TextButtonTheme(data: data, child: child);
|
|
}
|
|
|
|
@override
|
|
bool updateShouldNotify(TextButtonTheme oldWidget) => data != oldWidget.data;
|
|
}
|