Skip to content

Commit

Permalink
wip: Remove influxui dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Aug 17, 2024
1 parent 770ec49 commit c3525c6
Show file tree
Hide file tree
Showing 19 changed files with 1,150 additions and 23 deletions.
1 change: 0 additions & 1 deletion apps/biyi_app/dart_dependency_validator.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
ignore:
- influxui
- vclibs
3 changes: 2 additions & 1 deletion apps/biyi_app/lib/app/home/limited_functionality_banner.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/utils/extended_colors.dart';
import 'package:biyi_app/utils/utils.dart';
import 'package:biyi_app/widgets/alert/alert.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/gestures.dart';
import 'package:influxui/influxui.dart' show Alert, AlertType, ExtendedColors;
import 'package:reflect_ui/reflect_ui.dart' hide Alert;
import 'package:screen_capturer/screen_capturer.dart';
import 'package:screen_text_extractor/screen_text_extractor.dart';
Expand Down
4 changes: 1 addition & 3 deletions apps/biyi_app/lib/app/settings/keybinds/page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
import 'package:biyi_app/widgets/kbd/kbd.dart';
import 'package:biyi_app/widgets/list_section.dart';
import 'package:biyi_app/widgets/list_tile.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart' show Scaffold;
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
import 'package:influxui/influxui.dart' show ExtendedSize, Kbd;
import 'package:provider/provider.dart';
import 'package:uni_platform/uni_platform.dart';

Expand All @@ -28,7 +28,6 @@ class HotKeyDisplayView extends StatelessWidget {
for (final HotKeyModifier modifier in hotKey.modifiers ?? []) ...[
Kbd(
modifier.physicalKeys.first.keyLabel,
size: ExtendedSize.small,
),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 4),
Expand All @@ -43,7 +42,6 @@ class HotKeyDisplayView extends StatelessWidget {
],
Kbd(
hotKey.physicalKey.keyLabel,
size: ExtendedSize.small,
),
],
);
Expand Down
3 changes: 1 addition & 2 deletions apps/biyi_app/lib/app/settings/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import 'dart:async';
import 'package:biyi_app/app/router_config.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/utils/extended_colors.dart';
import 'package:biyi_app/widgets/navigation_rail/navigation_rail.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
import 'package:go_router/go_router.dart';
import 'package:influxui/influxui.dart'
show NavigationRail, NavigationRailDestination;
import 'package:reflect_ui/reflect_ui.dart';
import 'package:uni_platform/uni_platform.dart';
import 'package:window_manager/window_manager.dart';
Expand Down
169 changes: 169 additions & 0 deletions apps/biyi_app/lib/widgets/alert/alert.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import 'package:biyi_app/utils/extended_colors.dart';
import 'package:biyi_app/widgets/alert/alert_style.dart';
import 'package:biyi_app/widgets/alert/alert_theme.dart';
import 'package:reflect_ui/reflect_ui.dart';

enum AlertType {
success,
info,
warning,
danger;
}

/// Attract user attention with important static message
class Alert extends StatefulWidget {
const Alert({
super.key,
this.style,
this.type = AlertType.info,
this.icon,
this.title,
this.titleBuilder,
this.message,
this.messageBuilder,
this.actions,
});

final AlertStyle? style;

/// Alert type
final AlertType? type;

final Widget? icon;

/// Alert title
final String? title;

/// Alert title builder
final WidgetBuilder? titleBuilder;

/// Alert message
final String? message;

/// Alert message builder
final WidgetBuilder? messageBuilder;

final List<Widget>? actions;

@override
State<Alert> createState() => _AlertState();
}

class _AlertState extends State<Alert> {
@override
Widget build(BuildContext context) {
final AlertThemeData? themeData = AlertTheme.of(context);
final AlertThemeData defaults = _AlertDefaults(context);
AlertStyle mergedStyle = widget.style ?? const AlertStyle();

switch (widget.type!) {
case AlertType.success:
mergedStyle = mergedStyle // merge success style
.merge(themeData?.successStyle)
.merge(defaults.successStyle);
break;
case AlertType.info:
mergedStyle = mergedStyle // merge info style
.merge(themeData?.infoStyle)
.merge(defaults.infoStyle);
break;
case AlertType.warning:
mergedStyle = mergedStyle // merge warning style
.merge(themeData?.warningStyle)
.merge(defaults.warningStyle);
break;
case AlertType.danger:
mergedStyle = mergedStyle // merge danger style
.merge(themeData?.dangerStyle)
.merge(defaults.dangerStyle);
break;
}

final Widget? iconWidget = widget.icon != null
? IconTheme(
data: IconThemeData(
size: mergedStyle.iconSize,
color: mergedStyle.titleStyle!.color,
),
child: widget.icon!,
)
: null;

final Widget? titleWidget = widget.titleBuilder != null
? widget.titleBuilder!(context)
: widget.title != null
? Text(widget.title!)
: null;

final Widget? messageWidget = widget.messageBuilder != null
? widget.messageBuilder!(context)
: widget.message != null
? Text(widget.message!)
: null;

return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: mergedStyle.backgroundColor,
),
child: GappedRow(
gap: 8,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (iconWidget != null) iconWidget,
Expanded(
child: GappedColumn(
gap: 8,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (titleWidget != null)
DefaultTextStyle(
style: mergedStyle.titleStyle!,
child: titleWidget,
),
if (messageWidget != null)
DefaultTextStyle(
style: mergedStyle.messageStyle!,
child: messageWidget,
),
if ((widget.actions ?? []).isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 4),
child: GappedRow(gap: 8, children: widget.actions!),
),
],
),
),
],
),
);
}
}

class _AlertDefaults extends AlertThemeData {
_AlertDefaults(this.context) : super();

final BuildContext context;
late final ThemeData _theme = Theme.of(context);

@override
AlertStyle? get successStyle {
return AlertStyle.fromColor(_theme, ExtendedColors.green);
}

@override
AlertStyle? get infoStyle {
return AlertStyle.fromColor(_theme, ExtendedColors.blue);
}

@override
AlertStyle? get warningStyle {
return AlertStyle.fromColor(_theme, ExtendedColors.yellow);
}

@override
AlertStyle? get dangerStyle {
return AlertStyle.fromColor(_theme, ExtendedColors.red);
}
}
65 changes: 65 additions & 0 deletions apps/biyi_app/lib/widgets/alert/alert_style.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' show MaterialColor, ThemeData;
import 'package:flutter/widgets.dart';

class AlertStyle with Diagnosticable {
const AlertStyle({
this.backgroundColor,
this.iconSize,
this.titleStyle,
this.messageStyle,
});

factory AlertStyle.fromColor(ThemeData theme, MaterialColor color) {
return AlertStyle(
backgroundColor: color.shade50,
iconSize: 20,
titleStyle: theme.textTheme.bodyMedium?.copyWith(
color: color.shade700,
fontWeight: FontWeight.w600,
),
messageStyle: theme.textTheme.bodyMedium?.copyWith(
color: color.shade600,
),
);
}

final Color? backgroundColor;

final double? iconSize;

final TextStyle? titleStyle;

final TextStyle? messageStyle;

AlertStyle copyWith({
Color? backgroundColor,
double? iconSize,
TextStyle? titleStyle,
TextStyle? messageStyle,
}) {
return AlertStyle(
backgroundColor: backgroundColor ?? this.backgroundColor,
iconSize: iconSize ?? this.iconSize,
titleStyle: titleStyle ?? this.titleStyle,
messageStyle: messageStyle ?? this.messageStyle,
);
}

/// Returns a copy of this AlertStyle where the non-null fields in [style]
/// have replaced the corresponding null fields in this AlertStyle.
///
/// In other words, [style] is used to fill in unspecified (null) fields
/// this AlertStyle.
AlertStyle merge(AlertStyle? style) {
if (style == null) {
return this;
}
return copyWith(
backgroundColor: style.backgroundColor,
iconSize: iconSize ?? style.iconSize,
titleStyle: titleStyle ?? style.titleStyle,
messageStyle: messageStyle ?? style.messageStyle,
);
}
}
47 changes: 47 additions & 0 deletions apps/biyi_app/lib/widgets/alert/alert_theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ignore_for_file: annotate_overrides

import 'package:biyi_app/widgets/alert/alert_style.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:theme_tailor_annotation/theme_tailor_annotation.dart';

part 'alert_theme.tailor.dart';

@TailorMixin()
class AlertThemeData extends ThemeExtension<AlertThemeData>
with DiagnosticableTreeMixin, _$AlertThemeDataTailorMixin {
const AlertThemeData({
this.successStyle,
this.infoStyle,
this.warningStyle,
this.dangerStyle,
});

final AlertStyle? successStyle;
final AlertStyle? infoStyle;
final AlertStyle? warningStyle;
final AlertStyle? dangerStyle;
}

class AlertTheme extends InheritedTheme {
const AlertTheme({
super.key,
required this.data,
required super.child,
});

final AlertThemeData data;

static AlertThemeData? of(BuildContext context) {
final theme = context.dependOnInheritedWidgetOfExactType<AlertTheme>();
return theme?.data ?? Theme.of(context).extension<AlertThemeData>();
}

@override
Widget wrap(BuildContext context, Widget child) {
return AlertTheme(data: data, child: child);
}

@override
bool updateShouldNotify(AlertTheme oldWidget) => data != oldWidget.data;
}
Loading

0 comments on commit c3525c6

Please sign in to comment.