Yijing Huang 8541ca8bec
Feat(appflowy_flutter): dark mode improvement for generic area/widgets (#2099)
* chore: update color scheme for dark mode

* chore: update dark color scheme

1. update the background color for side bar, surface and divider in dark mode
2. comment out dandelion and lavender theme temporarily

* chore: update top bar BGcolor and icon color

* chore: update text color

* chore: update share button color on the top bar

* chore: add tooltip theme data in global

* chore: add hint and tertiary color and update font size pop up menu style

* chore: update all the semibold texts color

* chore: update all the hover color

* chore: update setting BG color

* chore: add FlowySvg to get the icon color through current theme

1. Add FlowySvg widget
2. Update all the icons those have hover effect to FlowySvg
3. Recover shader1 for the text color when it is in hovered

* chore: update side bar UI

1. Update AddButton hover style
2. Update MenuAppHeader icon color and its hover style
3. Update NewAppButton(New page) font color
4. Update MenuUser username font color

* chore: update SettingsDialog style in dart mode

    1. Update title and text color
    2. Update the hover color on FlowyTextButton
    3. Update the LanguageSelectorDropdown background color and hover enter color

* chore: update NewAppButton icon in dark mode

* chore: update default icon color

* chore: rename the hover color and update ViewSectionItem hover color from default theme color

* chore: add question bubble background color

* chore: update cover image button color

* chore: remove fixed icon color on _AddCoverButton

* chore: put Dandelion and Lavender color scheme back with basic modification

* fix: delete unused import files and deprecated field

* chore: add comma and put color back

* chore: update AppFlowyPopover background color

* chore: remove the hover color on primary and secondary button

* chore: update shadow color in dark mode

* chore: update SettingsMenuElement hover effect

* chore: update the text color in DropdownMenuItem
2023-03-30 09:44:37 +08:00

187 lines
5.4 KiB
Dart

import 'dart:io';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/image.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart';
import 'package:styled_widget/styled_widget.dart';
typedef NaviAction = void Function();
class NavigationNotifier with ChangeNotifier {
List<NavigationItem> navigationItems;
NavigationNotifier({required this.navigationItems});
void update(HomeStackNotifier notifier) {
bool shouldNotify = false;
if (navigationItems != notifier.plugin.display.navigationItems) {
navigationItems = notifier.plugin.display.navigationItems;
shouldNotify = true;
}
if (shouldNotify) {
notifyListeners();
}
}
}
class FlowyNavigation extends StatelessWidget {
const FlowyNavigation({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProxyProvider<HomeStackNotifier, NavigationNotifier>(
create: (_) {
final notifier = Provider.of<HomeStackNotifier>(context, listen: false);
return NavigationNotifier(
navigationItems: notifier.plugin.display.navigationItems,
);
},
update: (_, notifier, controller) => controller!..update(notifier),
child: Expanded(
child: Row(children: [
_renderCollapse(context),
Selector<NavigationNotifier, List<NavigationItem>>(
selector: (context, notifier) => notifier.navigationItems,
builder: (ctx, items, child) => Expanded(
child: Row(
children: _renderNavigationItems(items),
// crossAxisAlignment: WrapCrossAlignment.start,
),
),
),
]),
),
);
}
Widget _renderCollapse(BuildContext context) {
return BlocBuilder<HomeSettingBloc, HomeSettingState>(
buildWhen: (p, c) => p.isMenuCollapsed != c.isMenuCollapsed,
builder: (context, state) {
if (state.isMenuCollapsed) {
return RotationTransition(
turns: const AlwaysStoppedAnimation(180 / 360),
child: Tooltip(
richMessage: sidebarTooltipTextSpan(
context,
LocaleKeys.sideBar_openSidebar.tr(),
),
child: FlowyIconButton(
width: 24,
hoverColor: Colors.transparent,
onPressed: () {
context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.collapseMenu());
},
iconPadding: const EdgeInsets.fromLTRB(2, 2, 2, 2),
icon: svgWidget(
"home/hide_menu",
color: Theme.of(context).iconTheme.color,
),
)),
);
} else {
return Container();
}
},
);
}
List<Widget> _renderNavigationItems(List<NavigationItem> items) {
if (items.isEmpty) {
return [];
}
List<NavigationItem> newItems = _filter(items);
Widget last = NaviItemWidget(newItems.removeLast());
List<Widget> widgets = List.empty(growable: true);
// widgets.addAll(newItems.map((item) => NaviItemDivider(child: NaviItemWidget(item))).toList());
for (final item in newItems) {
widgets.add(NaviItemWidget(item));
widgets.add(const Text('/'));
}
widgets.add(last);
return widgets;
}
List<NavigationItem> _filter(List<NavigationItem> items) {
final length = items.length;
if (length > 4) {
final first = items[0];
final ellipsisItems = items.getRange(1, length - 2).toList();
final last = items.getRange(length - 2, length).toList();
return [
first,
EllipsisNaviItem(items: ellipsisItems),
...last,
];
} else {
return items;
}
}
}
class NaviItemWidget extends StatelessWidget {
final NavigationItem item;
const NaviItemWidget(this.item, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Expanded(
child: item.leftBarItem.padding(horizontal: 2, vertical: 2));
}
}
class NaviItemDivider extends StatelessWidget {
final Widget child;
const NaviItemDivider({Key? key, required this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [child, const Text('/')],
);
}
}
class EllipsisNaviItem extends NavigationItem {
final List<NavigationItem> items;
EllipsisNaviItem({
required this.items,
});
@override
Widget get leftBarItem => FlowyText.medium(
'...',
fontSize: FontSizes.s16,
);
@override
NavigationCallback get action => (id) {};
}
TextSpan sidebarTooltipTextSpan(BuildContext context, String hintText) =>
TextSpan(
children: [
TextSpan(
text: "$hintText\n",
),
TextSpan(
text: Platform.isMacOS ? "⌘+\\" : "Ctrl+\\",
),
],
);