Skip to content

Commit

Permalink
Clean up some common widgets (#6117)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Jul 28, 2023
1 parent 16d261c commit 530dfa1
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 136 deletions.
49 changes: 17 additions & 32 deletions packages/devtools_app/lib/src/framework/about_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,21 @@ class _DiscordLink extends StatelessWidget {
}
}

class OpenAboutAction extends StatelessWidget {
const OpenAboutAction({super.key, this.color});

final Color? color;

@override
Widget build(BuildContext context) {
final releaseNotesController = Provider.of<ReleaseNotesController>(context);
return DevToolsTooltip(
message: 'About DevTools',
child: InkWell(
onTap: () {
unawaited(
showDialog(
context: context,
builder: (context) => DevToolsAboutDialog(releaseNotesController),
),
);
},
child: Container(
width: actionWidgetSize,
height: actionWidgetSize,
alignment: Alignment.center,
child: Icon(
Icons.help_outline,
size: actionsIconSize,
color: color,
),
),
),
);
}
class OpenAboutAction extends ScaffoldAction {
OpenAboutAction({super.key, Color? color})
: super(
icon: Icons.help_outline,
tooltip: 'About DevTools',
color: color,
onPressed: (context) {
unawaited(
showDialog(
context: context,
builder: (context) => DevToolsAboutDialog(
Provider.of<ReleaseNotesController>(context),
),
),
);
},
);
}
53 changes: 18 additions & 35 deletions packages/devtools_app/lib/src/framework/report_feedback_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,25 @@ import '../shared/analytics/constants.dart' as gac;
import '../shared/common_widgets.dart';
import '../shared/config_specific/launch_url/launch_url.dart';
import '../shared/globals.dart';
import '../shared/theme.dart';

/// Button that, when clicked, will open the DevTools issue tracker in the
/// browser.
class ReportFeedbackButton extends StatelessWidget {
const ReportFeedbackButton({super.key, this.color});

final Color? color;

@override
Widget build(BuildContext context) {
return DevToolsTooltip(
message: 'Report feedback',
child: InkWell(
onTap: () {
ga.select(
gac.devToolsMain,
gac.feedbackButton,
);
unawaited(
launchUrl(
devToolsExtensionPoints.issueTrackerLink().url,
),
);
},
child: Container(
width: actionWidgetSize,
height: actionWidgetSize,
alignment: Alignment.center,
child: Icon(
Icons.bug_report_outlined,
size: actionsIconSize,
color: color,
),
),
),
);
}
class ReportFeedbackButton extends ScaffoldAction {
ReportFeedbackButton({super.key, Color? color})
: super(
icon: Icons.bug_report_outlined,
tooltip: 'Report feedback',
color: color,
onPressed: (_) {
ga.select(
gac.devToolsMain,
gac.feedbackButton,
);
unawaited(
launchUrl(
devToolsExtensionPoints.issueTrackerLink().url,
),
);
},
);
}
46 changes: 15 additions & 31 deletions packages/devtools_app/lib/src/framework/settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,21 @@ import '../shared/log_storage.dart';
import '../shared/theme.dart';
import '../shared/utils.dart';

class OpenSettingsAction extends StatelessWidget {
const OpenSettingsAction({super.key, this.color});

final Color? color;

@override
Widget build(BuildContext context) {
return DevToolsTooltip(
message: 'Settings',
child: InkWell(
onTap: () {
unawaited(
showDialog(
context: context,
builder: (context) => const SettingsDialog(),
),
);
},
child: Container(
width: actionWidgetSize,
height: actionWidgetSize,
alignment: Alignment.center,
child: Icon(
Icons.settings_outlined,
size: actionsIconSize,
color: color,
),
),
),
);
}
class OpenSettingsAction extends ScaffoldAction {
OpenSettingsAction({super.key, Color? color})
: super(
icon: Icons.settings_outlined,
tooltip: 'Settings',
color: color,
onPressed: (context) {
unawaited(
showDialog(
context: context,
builder: (context) => const SettingsDialog(),
),
);
},
);
}

class SettingsDialog extends StatelessWidget {
Expand Down
50 changes: 46 additions & 4 deletions packages/devtools_app/lib/src/shared/common_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,22 @@ TextStyle primaryColorLight(TextStyle style, BuildContext context) {
class DevToolsButton extends StatelessWidget {
const DevToolsButton({
Key? key,
required this.icon,
required this.onPressed,
required this.gaScreen,
required this.gaSelection,
this.icon,
this.label,
this.color,
this.minScreenWidthForTextBeforeScaling,
this.elevatedButton = false,
this.tooltip,
this.tooltipPadding,
this.outlined = true,
}) : super(key: key);
}) : assert(
label != null || icon != null,
'Either icon or label must be specified.',
),
super(key: key);

factory DevToolsButton.iconOnly({
required IconData icon,
Expand All @@ -140,8 +144,7 @@ class DevToolsButton extends StatelessWidget {
);
}

// TODO(kenz): allow icon to be nullable if this is a text only button.
final IconData icon;
final IconData? icon;

final String? label;

Expand Down Expand Up @@ -835,6 +838,45 @@ class ToolbarAction extends StatelessWidget {
}
}

/// Icon action button used in the main DevTools toolbar or footer.
abstract class ScaffoldAction extends StatelessWidget {
const ScaffoldAction({
super.key,
required this.icon,
required this.tooltip,
required this.onPressed,
this.color,
});

final IconData icon;

final String tooltip;

final Function(BuildContext) onPressed;

final Color? color;

@override
Widget build(BuildContext context) {
return DevToolsTooltip(
message: tooltip,
child: InkWell(
onTap: () => onPressed(context),
child: Container(
width: actionWidgetSize,
height: actionWidgetSize,
alignment: Alignment.center,
child: Icon(
icon,
size: actionsIconSize,
color: color,
),
),
),
);
}
}

/// A blank, drop-in replacement for [AreaPaneHeader].
///
/// Acts as an empty header widget with zero size that is compatible with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import '../../globals.dart';
import '../../primitives/simple_items.dart';
import '../../primitives/utils.dart';
import '../../screen.dart';
import '../../theme.dart';
import '_export_stub.dart'
if (dart.library.html) '_export_web.dart'
if (dart.library.io) '_export_desktop.dart';
Expand Down Expand Up @@ -187,32 +186,16 @@ abstract class ExportController {
}
}

class ImportToolbarAction extends StatelessWidget {
const ImportToolbarAction({super.key, this.color});
class ImportToolbarAction extends ScaffoldAction {
ImportToolbarAction({super.key, Color? color})
: super(
icon: Icons.upload_rounded,
tooltip: 'Load data for viewing in DevTools.',
color: color,
onPressed: (context) => unawaited(_importFile(context)),
);

final Color? color;

@override
Widget build(BuildContext context) {
return DevToolsTooltip(
message: 'Load data for viewing in DevTools.',
child: InkWell(
onTap: () => unawaited(_importFile(context)),
child: Container(
width: actionWidgetSize,
height: actionWidgetSize,
alignment: Alignment.center,
child: Icon(
Icons.upload_rounded,
size: actionsIconSize,
color: color,
),
),
),
);
}

Future<void> _importFile(BuildContext context) async {
static Future<void> _importFile(BuildContext context) async {
ga.select(
gac.devToolsMain,
gac.importFile,
Expand Down
22 changes: 14 additions & 8 deletions packages/devtools_app/lib/src/shared/ui/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ class MaterialIconLabel extends StatelessWidget {
required this.iconData,
this.color,
this.minScreenWidthForTextBeforeScaling,
});
}) : assert(
label != null || iconData != null,
'Either iconData or label must be specified.',
);

final IconData iconData;
final IconData? iconData;
final Color? color;
final String? label;
final double? minScreenWidthForTextBeforeScaling;
Expand All @@ -58,16 +61,19 @@ class MaterialIconLabel extends StatelessWidget {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
iconData,
size: defaultIconSize,
color: color,
),
if (iconData != null)
Icon(
iconData,
size: defaultIconSize,
color: color,
),
// TODO(jacobr): animate showing and hiding the text.
if (label != null &&
includeText(context, minScreenWidthForTextBeforeScaling))
Padding(
padding: const EdgeInsets.only(left: denseSpacing),
padding: EdgeInsets.only(
left: iconData != null ? denseSpacing : 0.0,
),
child: Text(
label!,
style: TextStyle(color: color),
Expand Down

0 comments on commit 530dfa1

Please sign in to comment.