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 {
Key key,
this.title,
this.titlePadding = const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0),
this.titleTextStyle,
this.children,
this.contentPadding = const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0),
this.backgroundColor,
......@@ -739,6 +740,12 @@ class SimpleDialog extends StatelessWidget {
/// [title] and the [children].
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
/// [SingleChildScrollView] underneath the title.
///
......@@ -814,7 +821,7 @@ class SimpleDialog extends StatelessWidget {
Padding(
padding: titlePadding,
child: DefaultTextStyle(
style: theme.textTheme.headline6,
style: titleTextStyle ?? DialogTheme.of(context).titleTextStyle ?? theme.textTheme.headline6,
child: Semantics(namesRoute: true, child: title),
),
),
......
......@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.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(
theme: theme,
home: Material(
......@@ -37,8 +37,8 @@ Material _getMaterialFromDialog(WidgetTester tester) {
return tester.widget<Material>(find.descendant(of: find.byType(AlertDialog), matching: find.byType(Material)));
}
RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.descendant(of: find.byType(AlertDialog), matching: find.text(text))).renderObject as RenderParagraph;
RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.text(text)).renderObject as RenderParagraph;
}
void main() {
......@@ -70,7 +70,7 @@ void main() {
);
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.pumpAndSettle();
......@@ -87,7 +87,7 @@ void main() {
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(elevation: customElevation));
await tester.pumpWidget(
_appWithAlertDialog(tester, dialog, theme: theme)
_appWithDialog(tester, dialog, theme: theme)
);
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -106,7 +106,7 @@ void main() {
final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(shape: customBorder));
await tester.pumpWidget(
_appWithAlertDialog(tester, dialog, theme: theme)
_appWithDialog(tester, dialog, theme: theme)
);
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
......@@ -124,7 +124,7 @@ void main() {
);
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.pumpAndSettle();
......@@ -143,11 +143,11 @@ void main() {
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_appWithDialog(tester, dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObjectFromDialog(tester, titleText);
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style, titleTextStyle);
});
......@@ -160,11 +160,11 @@ void main() {
);
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.pumpAndSettle();
final RenderParagraph title = _getTextRenderObjectFromDialog(tester, titleText);
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style, titleTextStyle);
});
......@@ -177,11 +177,59 @@ void main() {
);
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.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);
});
......@@ -194,11 +242,11 @@ void main() {
actions: <Widget>[ ],
);
await tester.pumpWidget(_appWithAlertDialog(tester, dialog));
await tester.pumpWidget(_appWithDialog(tester, dialog));
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText);
final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style, contentTextStyle);
});
......@@ -211,11 +259,11 @@ void main() {
);
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.pumpAndSettle();
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText);
final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style, contentTextStyle);
});
......@@ -228,11 +276,11 @@ void main() {
);
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.pumpAndSettle();
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText);
final RenderParagraph content = _getTextRenderObject(tester, contentText);
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