Skip to content

Commit

Permalink
fix: #1518 - normal size for most alert dialogs (#1519)
Browse files Browse the repository at this point in the history
Deleted file:
* `product_list_dialog_helper.dart`

Impacted files:
* `basic_test.dart`: refactored
* `loading_dialog.dart`: refactored
* `product_dialog_helper.dart`: refactored
* `smooth_alert_dialog.dart`: now constructors for simple and advanced effects
* `user_contribution_view.dart`: now explicitly using the "advanced" dialog
* `user_preferences_profile.dart`: refactored
* `user_preferences_settings.dart`: now explicitly using the "advanced" dialog
  • Loading branch information
monsieurtanuki authored Apr 8, 2022
1 parent 4449a9f commit 1199c79
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 114 deletions.
107 changes: 54 additions & 53 deletions packages/smooth_app/lib/generic_lib/dialogs/smooth_alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,44 @@ import 'package:smooth_app/generic_lib/design_constants.dart';
///
class SmoothAlertDialog extends StatelessWidget {
/// The most simple alert dialog: no fancy effects.
const SmoothAlertDialog({
this.title,
required this.body,
required this.actions,
}) : close = false,
maxHeight = null,
_simpleMode = true;

/// Advanced alert dialog with fancy effects.
const SmoothAlertDialog.advanced({
this.title,
this.close = true,
this.maxHeight,
required this.body,
this.actions,
});
}) : _simpleMode = false;

final String? title;
final bool close;
final double? maxHeight;
final Widget body;
final List<SmoothActionButton>? actions;
final bool _simpleMode;

@override
Widget build(BuildContext context) {
final Widget content = _buildContent(context);
return AlertDialog(
elevation: 4,
shape: const RoundedRectangleBorder(
borderRadius: ROUNDED_BORDER_RADIUS,
),
content: ConstrainedBox(
constraints:
BoxConstraints(maxHeight: maxHeight ?? double.infinity * 0.5),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (title != null) ...<Widget>[
SizedBox(
height: 32,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
_buildCross(true, context),
if (title != null)
Expanded(
child: FittedBox(
child: Text(
title!,
style: Theme.of(context).textTheme.headline2,
),
),
),
_buildCross(false, context),
],
),
),
Divider(
color: Theme.of(context).colorScheme.onBackground,
),
const SizedBox(
height: 12,
),
],
Expanded(
child: SingleChildScrollView(
child: body,
),
shape: const RoundedRectangleBorder(borderRadius: ROUNDED_BORDER_RADIUS),
content: _simpleMode
? content
: ConstrainedBox(
constraints:
BoxConstraints(maxHeight: maxHeight ?? double.infinity * 0.5),
child: content,
),
],
),
),
actions: actions == null
? null
: <Widget>[
Expand Down Expand Up @@ -112,12 +87,38 @@ class SmoothAlertDialog extends StatelessWidget {
return Container();
}
}
}

///
/// final String title;
/// final bool close;
/// final Widget body;
/// final List<SmoothActionButton> actions;
/// final double height;
///
Widget _buildContent(final BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (title != null) ...<Widget>[
SizedBox(
height: 32,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
_buildCross(true, context),
if (title != null)
Expanded(
child: FittedBox(
child: Text(
title!,
style: Theme.of(context).textTheme.headline2,
),
),
),
_buildCross(false, context),
],
),
),
Divider(color: Theme.of(context).colorScheme.onBackground),
const SizedBox(height: 12),
],
if (_simpleMode)
body
else
Expanded(child: SingleChildScrollView(child: body)),
],
);
}
2 changes: 0 additions & 2 deletions packages/smooth_app/lib/generic_lib/loading_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class LoadingDialog<T> {
final AppLocalizations? appLocalizations =
AppLocalizations.of(context);
return SmoothAlertDialog(
close: false,
body: ListTile(
leading: const Icon(Icons.error),
title: Text(
Expand Down Expand Up @@ -90,7 +89,6 @@ class LoadingDialog<T> {
) {
final AppLocalizations? appLocalizations = AppLocalizations.of(context);
return SmoothAlertDialog(
close: false,
body: ListTile(
leading: const CircularProgressIndicator(),
title: Text(title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class ProductDialogHelper {
context: context,
builder: (BuildContext context) {
return SmoothAlertDialog(
close: false,
body: Text(
refresh
? AppLocalizations.of(context)!.could_not_refresh
Expand Down Expand Up @@ -77,7 +76,6 @@ class ProductDialogHelper {
void _openErrorMessage(final String message) => showDialog<void>(
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
close: false,
body: getErrorMessage(message),
actions: <SmoothActionButton>[
SmoothActionButton(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class _UserPreferencesPageState extends State<UserPreferencesSection> {
context: context,
builder: (BuildContext context) {
return SmoothAlertDialog(
close: false,
title: localizations.sign_out,
body: Text(
localizations.sign_out_confirmation,
Expand Down
5 changes: 2 additions & 3 deletions packages/smooth_app/lib/pages/user_preferences_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class UserPreferencesSettings extends AbstractUserPreferences {
onPressed: () {
showDialog<void>(
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
close: false,
builder: (BuildContext context) => SmoothAlertDialog.advanced(
body: Column(
children: <Widget>[
SmoothMainButton(
Expand Down Expand Up @@ -180,7 +179,7 @@ class UserPreferencesSettings extends AbstractUserPreferences {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
showDialog<void>(
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
builder: (BuildContext context) => SmoothAlertDialog.advanced(
close: false,
body: Column(
children: <Widget>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class UserContributionView extends StatelessWidget {
context: context,
builder: (BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context)!;
return SmoothAlertDialog(
return SmoothAlertDialog.advanced(
close: false,
maxHeight: MediaQuery.of(context).size.height * 0.35,
title: appLocalizations.contribute_improve_header,
Expand Down Expand Up @@ -123,7 +123,7 @@ class UserContributionView extends StatelessWidget {
context: context,
builder: (BuildContext context) {
final AppLocalizations applocalization = AppLocalizations.of(context)!;
return SmoothAlertDialog(
return SmoothAlertDialog.advanced(
maxHeight: MediaQuery.of(context).size.height * 0.35,
title: applocalization.contribute_sw_development,
body: Column(
Expand Down Expand Up @@ -184,7 +184,7 @@ class UserContributionView extends StatelessWidget {
context: context,
builder: (BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context)!;
return SmoothAlertDialog(
return SmoothAlertDialog.advanced(
title: appLocalizations.contribute_translate_header,
maxHeight: MediaQuery.of(context).size.height * 0.25,
body: Column(
Expand Down Expand Up @@ -221,7 +221,7 @@ class UserContributionView extends StatelessWidget {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return SmoothAlertDialog(
return SmoothAlertDialog.advanced(
title: AppLocalizations.of(context)!.contributors,
maxHeight: MediaQuery.of(context).size.height * 0.45,
body: FutureBuilder<http.Response>(
Expand Down
4 changes: 2 additions & 2 deletions packages/smooth_app/test/smooth_ui_library/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';

void main() {
testWidgets('Alert dialog can be created', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(home: SmoothAlertDialog(body: Placeholder())));
await tester.pumpWidget(const MaterialApp(
home: SmoothAlertDialog.advanced(body: Placeholder())));
expect(find.byType(SmoothAlertDialog), findsOneWidget);
});
}

0 comments on commit 1199c79

Please sign in to comment.