Skip to content

Commit

Permalink
Fix infobar on RTL languages
Browse files Browse the repository at this point in the history
  • Loading branch information
alesimula committed Jan 13, 2022
1 parent 1bb11e3 commit e14504b
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/screens/wsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:fluent_ui/fluent_ui.dart';
import 'package:mdi/mdi.dart';
import 'package:wsa_pacman/utils/wsa_utils.dart';
import 'package:wsa_pacman/widget/fluent_card.dart';
import 'package:wsa_pacman/widget/fluent_info_bar.dart';
import '../main.dart';
import '../global_state.dart';

Expand Down Expand Up @@ -64,7 +65,7 @@ class _ScreenWSAState extends State<ScreenWSA> {
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: InfoBar(
child: FluentInfoBar(
title: Text(connectionStatus.title(lang)),
content: Wrap(crossAxisAlignment: WrapCrossAlignment.center, children: [
Text(connectionStatus.desc(lang)),
Expand Down
3 changes: 2 additions & 1 deletion lib/widget/flexible_info_bar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' as material;
import 'package:wsa_pacman/widget/fluent_info_bar.dart';

class FlexibleInfoBar extends StatelessWidget {

Expand All @@ -24,7 +25,7 @@ class FlexibleInfoBar extends StatelessWidget {
Widget build(BuildContext context) {
return Flexible(child: LayoutBuilder(
builder: (context, BoxConstraints constraints) {
return InfoBar(
return FluentInfoBar(
title: SizedBox(
height: (constraints.maxHeight-25),// - (constraints.maxHeight-constr.maxHeight),
child: material.Scaffold(
Expand Down
139 changes: 139 additions & 0 deletions lib/widget/fluent_info_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import 'dart:ui';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';

class FluentInfoBar extends StatelessWidget {
/// Creates an info bar.
const FluentInfoBar({
Key? key,
required this.title,
this.content,
this.action,
this.severity = InfoBarSeverity.info,
this.style,
this.isLong = false,
this.onClose,
}) : super(key: key);

/// The severity of this InfoBar. Defaults to [InfoBarSeverity.info]
final InfoBarSeverity severity;

/// The style applied to this info bar. If non-null, it's
/// mescled with [ThemeData.infoBarThemeData]
final InfoBarThemeData? style;

final Widget title;
final Widget? content;
final Widget? action;

/// Called when the close button is pressed. If this is null,
/// there will be no close button
final void Function()? onClose;

/// If `true`, the info bar will be treated as long.
///
/// ![Long InfoBar](https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/images/infobar-success-content-wrapping.png)
final bool isLong;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(FlagProperty('long', value: isLong, ifFalse: 'short'))
..add(EnumProperty('severity', severity))
..add(ObjectFlagProperty.has('onClose', onClose))
..add(DiagnosticsProperty('style', style, ifNull: 'no style'));
}

@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
assert(debugCheckHasFluentLocalizations(context));
final localizations = FluentLocalizations.of(context);
final style = InfoBarTheme.of(context).merge(this.style);
final icon = style.icon?.call(severity);
final closeIcon = style.closeIcon;
final title = DefaultTextStyle(
style: FluentTheme.of(context).typography.bodyStrong ?? const TextStyle(),
child: this.title,
);
final content = () {
if (this.content == null) return null;
return DefaultTextStyle(
style: FluentTheme.of(context).typography.body ?? const TextStyle(),
child: this.content!,
softWrap: true,
);
}();
final action = () {
if (this.action == null) return null;
return ButtonTheme.merge(
child: this.action!,
data: ButtonThemeData.all(style.actionStyle),
);
}();
return Container(
decoration: style.decoration?.call(severity),
padding: style.padding ?? const EdgeInsets.all(10),
alignment: AlignmentDirectional.centerStart,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment:
isLong ? CrossAxisAlignment.start : CrossAxisAlignment.center,
children: [
if (icon != null)
Padding(
padding: const EdgeInsetsDirectional.only(end: 6.0),
child: Icon(icon, color: style.iconColor?.call(severity)),
),
if (isLong)
Flexible(
fit: FlexFit.loose,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
title,
if (content != null)
Padding(
padding: const EdgeInsets.only(top: 6.0),
child: content,
),
if (action != null)
Padding(
padding: const EdgeInsets.only(top: 6.0),
child: action,
),
],
),
)
else
Flexible(
fit: FlexFit.loose,
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 6,
children: [
title,
if (content != null) content,
if (action != null) action,
],
),
),
if (closeIcon != null && onClose != null)
Padding(
padding: const EdgeInsetsDirectional.only(start: 10.0),
child: Tooltip(
message: localizations.closeButtonLabel,
child: IconButton(
icon: Icon(closeIcon, size: style.closeIconSize),
onPressed: onClose,
style: style.closeButtonStyle,
),
),
),
],
),
);
}
}

0 comments on commit e14504b

Please sign in to comment.