Unverified Commit 0e7b2bef authored by rami-a's avatar rami-a Committed by GitHub

Use titleTextStyle from dialog theme for SimpleDialog (#56895)

parent 1bb9f3f7
...@@ -712,6 +712,7 @@ class SimpleDialog extends StatelessWidget { ...@@ -712,6 +712,7 @@ class SimpleDialog extends StatelessWidget {
Key key, Key key,
this.title, this.title,
this.titlePadding = const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0), this.titlePadding = const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0),
this.titleTextStyle,
this.children, this.children,
this.contentPadding = const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0), this.contentPadding = const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0),
this.backgroundColor, this.backgroundColor,
...@@ -739,6 +740,12 @@ class SimpleDialog extends StatelessWidget { ...@@ -739,6 +740,12 @@ class SimpleDialog extends StatelessWidget {
/// [title] and the [children]. /// [title] and the [children].
final EdgeInsetsGeometry titlePadding; final EdgeInsetsGeometry titlePadding;
/// Style for the text in the [title] of this [SimpleDialog].
///
/// If null, [DialogTheme.titleTextStyle] is used, if that's null, defaults to
/// [ThemeData.textTheme.headline6].
final TextStyle titleTextStyle;
/// The (optional) content of the dialog is displayed in a /// The (optional) content of the dialog is displayed in a
/// [SingleChildScrollView] underneath the title. /// [SingleChildScrollView] underneath the title.
/// ///
...@@ -814,7 +821,7 @@ class SimpleDialog extends StatelessWidget { ...@@ -814,7 +821,7 @@ class SimpleDialog extends StatelessWidget {
Padding( Padding(
padding: titlePadding, padding: titlePadding,
child: DefaultTextStyle( child: DefaultTextStyle(
style: theme.textTheme.headline6, style: titleTextStyle ?? DialogTheme.of(context).titleTextStyle ?? theme.textTheme.headline6,
child: Semantics(namesRoute: true, child: title), child: Semantics(namesRoute: true, child: title),
), ),
), ),
......
...@@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; ...@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
MaterialApp _appWithAlertDialog(WidgetTester tester, AlertDialog dialog, { ThemeData theme }) { MaterialApp _appWithDialog(WidgetTester tester, Widget dialog, { ThemeData theme }) {
return MaterialApp( return MaterialApp(
theme: theme, theme: theme,
home: Material( home: Material(
...@@ -37,8 +37,8 @@ Material _getMaterialFromDialog(WidgetTester tester) { ...@@ -37,8 +37,8 @@ Material _getMaterialFromDialog(WidgetTester tester) {
return tester.widget<Material>(find.descendant(of: find.byType(AlertDialog), matching: find.byType(Material))); return tester.widget<Material>(find.descendant(of: find.byType(AlertDialog), matching: find.byType(Material)));
} }
RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) { RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.descendant(of: find.byType(AlertDialog), matching: find.text(text))).renderObject as RenderParagraph; return tester.element<StatelessElement>(find.text(text)).renderObject as RenderParagraph;
} }
void main() { void main() {
...@@ -70,7 +70,7 @@ void main() { ...@@ -70,7 +70,7 @@ void main() {
); );
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(backgroundColor: customColor)); final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(backgroundColor: customColor));
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: theme)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -87,7 +87,7 @@ void main() { ...@@ -87,7 +87,7 @@ void main() {
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(elevation: customElevation)); final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(elevation: customElevation));
await tester.pumpWidget( await tester.pumpWidget(
_appWithAlertDialog(tester, dialog, theme: theme) _appWithDialog(tester, dialog, theme: theme)
); );
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -106,7 +106,7 @@ void main() { ...@@ -106,7 +106,7 @@ void main() {
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(shape: customBorder)); final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(shape: customBorder));
await tester.pumpWidget( await tester.pumpWidget(
_appWithAlertDialog(tester, dialog, theme: theme) _appWithDialog(tester, dialog, theme: theme)
); );
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -124,7 +124,7 @@ void main() { ...@@ -124,7 +124,7 @@ void main() {
); );
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(shape: customBorder)); final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(shape: customBorder));
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: theme)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
...@@ -143,11 +143,11 @@ void main() { ...@@ -143,11 +143,11 @@ void main() {
actions: <Widget>[ ], actions: <Widget>[ ],
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_appWithDialog(tester, dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObjectFromDialog(tester, titleText); final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style, titleTextStyle); expect(title.text.style, titleTextStyle);
}); });
...@@ -160,11 +160,11 @@ void main() { ...@@ -160,11 +160,11 @@ void main() {
); );
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(titleTextStyle: titleTextStyle)); final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(titleTextStyle: titleTextStyle));
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: theme)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObjectFromDialog(tester, titleText); final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style, titleTextStyle); expect(title.text.style, titleTextStyle);
}); });
...@@ -177,11 +177,59 @@ void main() { ...@@ -177,11 +177,59 @@ void main() {
); );
final ThemeData theme = ThemeData(textTheme: const TextTheme(headline6: titleTextStyle)); final ThemeData theme = ThemeData(textTheme: const TextTheme(headline6: titleTextStyle));
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: theme)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObjectFromDialog(tester, titleText); final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style.color, titleTextStyle.color);
});
testWidgets('Simple Dialog - Custom Title Text Style - Constructor Param', (WidgetTester tester) async {
const String titleText = 'Title';
const TextStyle titleTextStyle = TextStyle(color: Colors.pink);
const SimpleDialog dialog = SimpleDialog(
title: Text(titleText),
titleTextStyle: titleTextStyle,
);
await tester.pumpWidget(_appWithDialog(tester, dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style, titleTextStyle);
});
testWidgets('Simple Dialog - Custom Title Text Style - Dialog Theme', (WidgetTester tester) async {
const String titleText = 'Title';
const TextStyle titleTextStyle = TextStyle(color: Colors.pink);
const SimpleDialog dialog = SimpleDialog(
title: Text(titleText),
);
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(titleTextStyle: titleTextStyle));
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style, titleTextStyle);
});
testWidgets('Simple Dialog - Custom Title Text Style - Theme', (WidgetTester tester) async {
const String titleText = 'Title';
const TextStyle titleTextStyle = TextStyle(color: Colors.pink);
const SimpleDialog dialog = SimpleDialog(
title: Text(titleText),
);
final ThemeData theme = ThemeData(textTheme: const TextTheme(headline6: titleTextStyle));
await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style.color, titleTextStyle.color); expect(title.text.style.color, titleTextStyle.color);
}); });
...@@ -194,11 +242,11 @@ void main() { ...@@ -194,11 +242,11 @@ void main() {
actions: <Widget>[ ], actions: <Widget>[ ],
); );
await tester.pumpWidget(_appWithAlertDialog(tester, dialog)); await tester.pumpWidget(_appWithDialog(tester, dialog));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style, contentTextStyle); expect(content.text.style, contentTextStyle);
}); });
...@@ -211,11 +259,11 @@ void main() { ...@@ -211,11 +259,11 @@ void main() {
); );
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(contentTextStyle: contentTextStyle)); final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(contentTextStyle: contentTextStyle));
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: theme)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style, contentTextStyle); expect(content.text.style, contentTextStyle);
}); });
...@@ -228,11 +276,11 @@ void main() { ...@@ -228,11 +276,11 @@ void main() {
); );
final ThemeData theme = ThemeData(textTheme: const TextTheme(subtitle1: contentTextStyle)); final ThemeData theme = ThemeData(textTheme: const TextTheme(subtitle1: contentTextStyle));
await tester.pumpWidget(_appWithAlertDialog(tester, dialog, theme: theme)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme));
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style.color, contentTextStyle.color); expect(content.text.style.color, contentTextStyle.color);
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment