mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Theme Toggle Button for AppFlowy. Created by @rileyhawk1417 (#206)
* Added Theme Toggle * Modified translations
This commit is contained in:
@ -90,6 +90,10 @@
|
|||||||
"inlineCode": "Inline Code",
|
"inlineCode": "Inline Code",
|
||||||
"quote": "Quote Block"
|
"quote": "Quote Block"
|
||||||
},
|
},
|
||||||
|
"tooltip":{
|
||||||
|
"lightMode": "Switch to Light mode",
|
||||||
|
"darkMode": "Switch to Dark mode"
|
||||||
|
},
|
||||||
"contactsPage": {
|
"contactsPage": {
|
||||||
"title": "Contacts",
|
"title": "Contacts",
|
||||||
"whatsHappening": "What's happening this week?",
|
"whatsHappening": "What's happening this week?",
|
||||||
|
@ -90,6 +90,10 @@
|
|||||||
"inlineCode": "Codice in linea",
|
"inlineCode": "Codice in linea",
|
||||||
"quote": "Cita Blocco"
|
"quote": "Cita Blocco"
|
||||||
},
|
},
|
||||||
|
"tooltip":{
|
||||||
|
"lightMode" : "Passa alla modalità Luce",
|
||||||
|
"darkMode" : "Passa alla modalità Buio"
|
||||||
|
},
|
||||||
"contactsPage": {
|
"contactsPage": {
|
||||||
"title": "Contatti",
|
"title": "Contatti",
|
||||||
"whatsHappening": "Cosa accadrà la prossima settimana?",
|
"whatsHappening": "Cosa accadrà la prossima settimana?",
|
||||||
|
@ -90,6 +90,10 @@
|
|||||||
"inlineCode": "内联代码",
|
"inlineCode": "内联代码",
|
||||||
"quote": "块引用"
|
"quote": "块引用"
|
||||||
},
|
},
|
||||||
|
"tooltip":{
|
||||||
|
"lightMode" : "切换到灯光模式",
|
||||||
|
"darkMode" : "切换到暗模式"
|
||||||
|
},
|
||||||
"contactsPage": {
|
"contactsPage": {
|
||||||
"title": "联系人",
|
"title": "联系人",
|
||||||
"whatsHappening": "这周发生了哪些事?",
|
"whatsHappening": "这周发生了哪些事?",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:app_flowy/startup/startup.dart';
|
import 'package:app_flowy/startup/startup.dart';
|
||||||
|
import 'package:app_flowy/workspace/presentation/theme/theme_model.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra/theme.dart';
|
import 'package:flowy_infra/theme.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
@ -39,15 +40,16 @@ class ApplicationWidget extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => ChangeNotifierProvider(
|
||||||
|
create: (context) => ThemeModel(),
|
||||||
|
builder: (context, _) {
|
||||||
const ratio = 1.73;
|
const ratio = 1.73;
|
||||||
const minWidth = 800.0;
|
const minWidth = 800.0;
|
||||||
setWindowMinSize(const Size(minWidth, minWidth / ratio));
|
setWindowMinSize(const Size(minWidth, minWidth / ratio));
|
||||||
// const launchWidth = 1310.0;
|
|
||||||
// setWindowFrame(const Rect.fromLTWH(0, 0, launchWidth, launchWidth / ratio));
|
|
||||||
|
|
||||||
final theme = AppTheme.fromType(ThemeType.light);
|
ThemeType themeType = context.select<ThemeModel, ThemeType>((value) => value.theme);
|
||||||
theme.isDark = true;
|
AppTheme theme = AppTheme.fromType(themeType);
|
||||||
|
|
||||||
return Provider.value(
|
return Provider.value(
|
||||||
value: theme,
|
value: theme,
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
@ -61,7 +63,7 @@ class ApplicationWidget extends StatelessWidget {
|
|||||||
home: child,
|
home: child,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppGlobals {
|
class AppGlobals {
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:flowy_infra/theme.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ThemeModel extends ChangeNotifier with EquatableMixin {
|
||||||
|
ThemeType _theme = ThemeType.light;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props {
|
||||||
|
return [_theme];
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeType get theme => _theme;
|
||||||
|
|
||||||
|
set theme(ThemeType value) {
|
||||||
|
if (_theme != value) {
|
||||||
|
_theme = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void swapTheme() {
|
||||||
|
theme = (theme == ThemeType.light ? ThemeType.dark : ThemeType.light);
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,15 @@
|
|||||||
import 'package:app_flowy/startup/startup.dart';
|
import 'package:app_flowy/startup/startup.dart';
|
||||||
import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart';
|
import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart';
|
||||||
import 'package:flowy_infra/size.dart';
|
import 'package:flowy_infra/size.dart';
|
||||||
|
import 'package:flowy_infra/theme.dart';
|
||||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile;
|
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||||
//import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:app_flowy/workspace/presentation/theme/theme_model.dart';
|
||||||
|
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||||
|
|
||||||
class MenuUser extends StatelessWidget {
|
class MenuUser extends StatelessWidget {
|
||||||
final UserProfile user;
|
final UserProfile user;
|
||||||
@ -14,15 +17,18 @@ class MenuUser extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final theme = context.watch<AppTheme>();
|
||||||
return BlocProvider<MenuUserBloc>(
|
return BlocProvider<MenuUserBloc>(
|
||||||
create: (context) => getIt<MenuUserBloc>(param1: user)..add(const MenuUserEvent.initial()),
|
create: (context) => getIt<MenuUserBloc>(param1: user)..add(const MenuUserEvent.initial()),
|
||||||
child: BlocBuilder<MenuUserBloc, MenuUserState>(
|
child: BlocBuilder<MenuUserBloc, MenuUserState>(
|
||||||
builder: (context, state) => Row(
|
builder: (context, state) => Row(
|
||||||
children: [
|
children: [
|
||||||
_renderAvatar(context),
|
_renderAvatar(context),
|
||||||
const HSpace(12),
|
const HSpace(10),
|
||||||
_renderUserName(context),
|
_renderUserName(context),
|
||||||
const HSpace(4),
|
const HSpace(80),
|
||||||
|
(theme.isDark ? _renderLightMode(context) : _renderDarkMode(context)),
|
||||||
|
|
||||||
//ToDo: when the user is allowed to create another workspace,
|
//ToDo: when the user is allowed to create another workspace,
|
||||||
//we get the below block back
|
//we get the below block back
|
||||||
//_renderDropButton(context),
|
//_renderDropButton(context),
|
||||||
@ -47,13 +53,39 @@ class MenuUser extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.w300,
|
fontWeight: FontWeight.w300,
|
||||||
color: Colors.white,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _renderThemeToggle(BuildContext context) {
|
||||||
|
final theme = context.watch<AppTheme>();
|
||||||
|
return CircleAvatar(
|
||||||
|
backgroundColor: theme.surface,
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(theme.isDark ? Icons.dark_mode : Icons.light_mode),
|
||||||
|
color: (theme.textColor),
|
||||||
|
onPressed: () {
|
||||||
|
context.read<ThemeModel>().swapTheme();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _renderDarkMode(BuildContext context) {
|
||||||
|
return Tooltip(
|
||||||
|
message: LocaleKeys.tooltip_darkMode.tr(),
|
||||||
|
child: _renderThemeToggle(context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _renderLightMode(BuildContext context) {
|
||||||
|
return Tooltip(
|
||||||
|
message: LocaleKeys.tooltip_lightMode.tr(),
|
||||||
|
child: _renderThemeToggle(context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _renderUserName(BuildContext context) {
|
Widget _renderUserName(BuildContext context) {
|
||||||
String name = context.read<MenuUserBloc>().state.user.name;
|
String name = context.read<MenuUserBloc>().state.user.name;
|
||||||
if (name.isEmpty) {
|
if (name.isEmpty) {
|
||||||
|
Reference in New Issue
Block a user