Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
refactor(side_bar): brought back good old tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 21, 2021
1 parent 697d8da commit 4870db8
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 65 deletions.
184 changes: 126 additions & 58 deletions lib/components/side_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,152 @@ class _SideBarState extends State<SideBar> {
int? currentIndex;

@override
Widget build(final BuildContext context) => SizedBox(
height: double.infinity,
width: remToPx(2.3),
child: Stack(
children: <Widget>[
Align(
child: Container(
width: double.infinity,
padding: EdgeInsets.symmetric(
vertical: remToPx(0.5),
),
Widget build(final BuildContext context) {
final double totalWidth = remToPx(2.4);
final Size itemSize = Size(totalWidth, remToPx(1.7));
final double totalHeight = widget.items.length * itemSize.height;
final double tooltipFontSize =
Theme.of(context).textTheme.bodyText1!.fontSize! + remToPx(0.1);

return SizedBox(
height: double.infinity,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: SizedBox(
height: totalHeight + (itemSize.height / 2),
width: totalWidth,
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.horizontal(
right: Radius.circular(remToPx(0.5)),
),
),
),
),
),
Align(
alignment: Alignment.centerLeft,
child: SizedBox(
width: totalWidth,
child: Column(
mainAxisSize: MainAxisSize.min,
children: widget.items
.asMap()
.map(
(final int i, final BarItem x) {
final bool isHovered = currentIndex == i;
final Color? color = x.isActive
? Theme.of(context).primaryColor
: Theme.of(context).brightness == Brightness.dark
? Theme.of(context)
.textTheme
.bodyText1
?.color
?.withOpacity(
isHovered ? 0.5 : 0.7,
)
: isHovered
? Palette.gray[600]
: Palette.gray[500];

return MapEntry<int, Widget>(
i,
MouseRegion(
cursor: SystemMouseCursors.click,
onEnter: (final PointerEnterEvent event) {
setState(() {
currentIndex = i;
});
},
onExit: (final PointerExitEvent event) {
setState(() {
currentIndex = null;
});
},
child: GestureDetector(
onTap: x.onPressed,
child: SizedBox(
width: itemSize.width,
height: itemSize.height,
child: Icon(
x.icon,
size: remToPx(1.25),
color: color,
),
),
),
),
);
},
)
.values
.toList(),
),
),
),
IgnorePointer(
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.only(
left: totalWidth + remToPx(0.5),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: widget.items
.asMap()
.map(
(final int i, final BarItem x) {
final bool isHovered = currentIndex == i;
final Color? color = x.isActive
? Theme.of(context).primaryColor
: Theme.of(context).brightness == Brightness.dark
? Theme.of(context)
.textTheme
.bodyText1
?.color
?.withOpacity(
isHovered ? 0.5 : 0.7,
)
: isHovered
? Palette.gray[600]
: Palette.gray[500];

return MapEntry<int, Widget>(
i,
MouseRegion(
cursor: SystemMouseCursors.click,
onEnter: (final PointerEnterEvent event) {
setState(() {
currentIndex = i;
});
},
onExit: (final PointerExitEvent event) {
setState(() {
currentIndex = null;
});
},
child: GestureDetector(
onTap: x.onPressed,
child: Padding(
padding: EdgeInsets.symmetric(
vertical: remToPx(0.25),
),
child: Tooltip(
message: x.name,
child: Icon(
x.icon,
size: remToPx(1.25),
color: color,
(final int i, final BarItem x) => MapEntry<int, Widget>(
i,
AnimatedOpacity(
duration: const Duration(milliseconds: 150),
opacity: currentIndex == i ? 1 : 0,
child: AnimatedScale(
alignment: Alignment.centerLeft,
scale: currentIndex == i ? 1 : 0.8,
duration: const Duration(milliseconds: 100),
child: SizedBox(
height: itemSize.height,
child: Material(
color: Theme.of(context).cardColor,
borderRadius:
BorderRadius.circular(remToPx(0.3)),
elevation: 16,
child: Padding(
padding: EdgeInsets.symmetric(
vertical:
(itemSize.height - tooltipFontSize) /
4,
horizontal: remToPx(0.5),
),
child: Text(
x.name,
style: Theme.of(context)
.textTheme
.bodyText1
?.copyWith(
fontSize: tooltipFontSize,
),
),
),
),
),
),
);
},
),
),
)
.values
.toList(),
),
),
),
],
),
);
),
],
),
);
}
}
6 changes: 0 additions & 6 deletions lib/plugins/app_lifecycle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ abstract class AppLifecycle {
}

try {
// await FunctionUtils.tryLoop(
// DataStore.initialize,
// max: Platform.environment['RESPWND_INST'] == 'true' ? 30 : 1,
// interval: const Duration(seconds: 2),
// );
await DataStore.initialize();
} catch (err, trace) {
Logger.of('DataStore').error(
Expand All @@ -114,7 +109,6 @@ abstract class AppLifecycle {
}

Translator.t = settingsLocale ?? Translator.getSupportedTranslation();

Deeplink.link = ProtocolHandler.fromArgs(args);
preready = true;
events.dispatch(AppLifecycleEvents.preready);
Expand Down
2 changes: 1 addition & 1 deletion packages/utilx/lib/utilities/countries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ enum LanguageCountries {
}

extension LanguageCountriesUtils on LanguageCountries {
String get name => name.toUpperCase();
String get name => toString().split('.').last.toUpperCase();
String get country => LanguageCountryUtils.codeNameMap[this]!;
}

Expand Down

0 comments on commit 4870db8

Please sign in to comment.