mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-09-06 07:12:45 +00:00

* feat: dynamic theme plugin (init) * feat: provide fallback color if plugin becomes out of date (transparent) * feat: use applicationDocumentsDirectory to store plugins * chore: remove json files * fix: add toJson to resolve analyzer errors * fix: analyzer (unused imports) * feat: add code generation scripts for freezed files (call recursively in packages) * fix: revert changes to dry generation * feat: call directly into script * refactor: scripts try to be stateless :) * fix: path to code generation in toml * fix: generate script permissions * fix: path not correct in generate.sh * feat: modify execution permissions before executing scripts * chore: switch order of build_runner and easy_localizations * fix: fs is not valid duckscript cmd * chore: clean build_runner before executing * chore: upgrade freezed and build_runner attempt to resolve InvalidType error * fix: use exec cmd.exe to chmod * feat: add task to generate all files * chore: remove redundant task (Code Gen) * chore: remove json_annoation to dev_dependencies * fix: dropped & between commands * chore: rename file and class to FlowyDynamicPlugin * fix: dependency hell * fix: json annotation in colorscheme * fix: analyzer warnings * fix: duckscript runner for code generator * fix: try without setting file permissions * chore: move file picker to infra * chore: restructure project directory * feat: add BLoC components for consumers * chore: update dependencies in pubspec.yaml file * fix: file picker imports * feat: add new translations for features * feat: add new widgets to render upload * fix: import * feat: add text overflow * feat: use animated switcher * chore: export FileType * fix: directory was not created, only files were copied * chore: separate some logic * feat: add saveFile to FilePickerService * fix: analyzer error with unused imports * feat: add translations for uploading * feat: add builtins property to apptheme * feat: add theme preview widget * fix: upload widgets need to fill whole space and account for overflow * refactor: do not watch file system for changes * feat: add deletion confirmation dialog * feat: add form factor resolution for dyanmic layout * feat: trigger rebuild only when plugins are loaded * feat: make all methods static * chore: remove TODO comment, requires further design * chore: move models to subfolder * fix: references to plugin service instance * fix: rebase errors * fix: more rebasing errors * feat: remove multiple themes from one plugin * refactor: use pattern to resolve widget in settings_appearance_view * refactor: remove commented code * feat: add translations * fix: import error * refactor: separate concerns a bit more * fix: bug in toJson serialization code * feat: add package to use represent memory files * fix: analyzer warnings * chore: add translation * chore: remove unused exceptions * chore: use join * chore: add documentation * feat: add tests on theme * fix: fix scripts for macOS * feat: use appFlowyDocumentDirectory * fix: remove unused import * fix: imports * feat: allow plugin service to be passed * fix: theme tests * feat: separate themes by built-in and plugin * fix: rebase change name of appFlowyDocumentDirectory * chore: add test to check that initial state falls back to initial theme * chore: theme upload preview widget * chore: rename to brightness setting * refactor: appearance for settings appearance view * feat: change show dialog api and use it * fix: handle plugin compilation exception when incorrect format supplied * fix: style of theme upload * fix: always change state so that ui updates * chore: style of loading widget * fix: analyzer errors * feat: add learn more button to documentation --------- Co-authored-by: Yijing Huang <hyj891204@gmail.com> Co-authored-by: nathan <nathan@appflowy.io>
292 lines
7.6 KiB
Dart
292 lines
7.6 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:appflowy/workspace/application/settings/prelude.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flowy_infra/file_picker/file_picker_service.dart';
|
|
import 'package:flowy_infra/image.dart';
|
|
import 'package:flowy_infra/size.dart';
|
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
import '../../../generated/locale_keys.g.dart';
|
|
import '../../../startup/startup.dart';
|
|
import '../../../workspace/presentation/home/toast.dart';
|
|
|
|
enum _FolderPage {
|
|
options,
|
|
create,
|
|
open,
|
|
}
|
|
|
|
class FolderWidget extends StatefulWidget {
|
|
const FolderWidget({
|
|
super.key,
|
|
required this.createFolderCallback,
|
|
});
|
|
|
|
final Future<void> Function() createFolderCallback;
|
|
|
|
@override
|
|
State<FolderWidget> createState() => _FolderWidgetState();
|
|
}
|
|
|
|
class _FolderWidgetState extends State<FolderWidget> {
|
|
var page = _FolderPage.options;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return _mapIndexToWidget(context);
|
|
}
|
|
|
|
Widget _mapIndexToWidget(BuildContext context) {
|
|
switch (page) {
|
|
case _FolderPage.options:
|
|
return FolderOptionsWidget(
|
|
onPressedOpen: () {
|
|
_openFolder();
|
|
},
|
|
);
|
|
case _FolderPage.create:
|
|
return CreateFolderWidget(
|
|
onPressedBack: () {
|
|
setState(() => page = _FolderPage.options);
|
|
},
|
|
onPressedCreate: widget.createFolderCallback,
|
|
);
|
|
case _FolderPage.open:
|
|
return Container();
|
|
}
|
|
}
|
|
|
|
Future<void> _openFolder() async {
|
|
final path = await getIt<FilePickerService>().getDirectoryPath();
|
|
if (path != null) {
|
|
await getIt<ApplicationDataStorage>().setCustomPath(path);
|
|
await widget.createFolderCallback();
|
|
setState(() {});
|
|
}
|
|
}
|
|
}
|
|
|
|
class FolderOptionsWidget extends StatelessWidget {
|
|
const FolderOptionsWidget({
|
|
super.key,
|
|
required this.onPressedOpen,
|
|
});
|
|
|
|
final VoidCallback onPressedOpen;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder(
|
|
future: getIt<ApplicationDataStorage>().getPath(),
|
|
builder: (context, result) {
|
|
final subtitle = result.hasData ? result.data! : '';
|
|
return _FolderCard(
|
|
icon: const FlowySvg(name: 'common/archive'),
|
|
title: LocaleKeys.settings_files_defineWhereYourDataIsStored.tr(),
|
|
subtitle: subtitle,
|
|
trailing: _buildTextButton(
|
|
context,
|
|
LocaleKeys.settings_files_set.tr(),
|
|
onPressedOpen,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class CreateFolderWidget extends StatefulWidget {
|
|
const CreateFolderWidget({
|
|
Key? key,
|
|
required this.onPressedBack,
|
|
required this.onPressedCreate,
|
|
}) : super(key: key);
|
|
|
|
final VoidCallback onPressedBack;
|
|
final Future<void> Function() onPressedCreate;
|
|
|
|
@override
|
|
State<CreateFolderWidget> createState() => CreateFolderWidgetState();
|
|
}
|
|
|
|
@visibleForTesting
|
|
class CreateFolderWidgetState extends State<CreateFolderWidget> {
|
|
var _folderName = 'appflowy';
|
|
@visibleForTesting
|
|
var directory = '';
|
|
|
|
final _fToast = FToast();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_fToast.init(context);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: TextButton.icon(
|
|
onPressed: widget.onPressedBack,
|
|
icon: const Icon(Icons.arrow_back_rounded),
|
|
label: const Text('Back'),
|
|
),
|
|
),
|
|
_FolderCard(
|
|
title: LocaleKeys.settings_files_location.tr(),
|
|
subtitle: LocaleKeys.settings_files_locationDesc.tr(),
|
|
trailing: SizedBox(
|
|
width: 120,
|
|
child: FlowyTextField(
|
|
hintText: LocaleKeys.settings_files_folderHintText.tr(),
|
|
onChanged: (name) => _folderName = name,
|
|
onSubmitted: (name) => setState(
|
|
() => _folderName = name,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
_FolderCard(
|
|
title: LocaleKeys.settings_files_folderPath.tr(),
|
|
subtitle: _path,
|
|
trailing: _buildTextButton(
|
|
context,
|
|
LocaleKeys.settings_files_browser.tr(),
|
|
() async {
|
|
final dir = await getIt<FilePickerService>().getDirectoryPath();
|
|
if (dir != null) {
|
|
setState(() => directory = dir);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
const VSpace(4.0),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
|
child: Row(
|
|
children: [
|
|
_buildTextButton(
|
|
context,
|
|
LocaleKeys.settings_files_create.tr(),
|
|
() async {
|
|
if (_path.isEmpty) {
|
|
_showToast(
|
|
LocaleKeys.settings_files_locationCannotBeEmpty.tr(),
|
|
);
|
|
} else {
|
|
await getIt<ApplicationDataStorage>().setCustomPath(_path);
|
|
await widget.onPressedCreate();
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
|
|
String get _path {
|
|
if (directory.isEmpty) return '';
|
|
final String path;
|
|
if (Platform.isMacOS) {
|
|
path = directory.replaceAll('/Volumes/Macintosh HD', '');
|
|
} else {
|
|
path = directory;
|
|
}
|
|
return '$path/$_folderName';
|
|
}
|
|
|
|
void _showToast(String message) {
|
|
_fToast.showToast(
|
|
child: FlowyMessageToast(message: message),
|
|
gravity: ToastGravity.CENTER,
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _buildTextButton(
|
|
BuildContext context,
|
|
String title,
|
|
VoidCallback onPressed,
|
|
) {
|
|
return SizedBox(
|
|
width: 60,
|
|
child: SecondaryTextButton(
|
|
title,
|
|
mode: SecondaryTextButtonMode.small,
|
|
onPressed: onPressed,
|
|
),
|
|
);
|
|
}
|
|
|
|
class _FolderCard extends StatelessWidget {
|
|
const _FolderCard({
|
|
required this.title,
|
|
required this.subtitle,
|
|
this.trailing,
|
|
this.icon,
|
|
});
|
|
|
|
final String title;
|
|
final String subtitle;
|
|
final Widget? icon;
|
|
final Widget? trailing;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 16.0,
|
|
horizontal: 16.0,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
if (icon != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 20),
|
|
child: icon!,
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
FlowyText.regular(
|
|
title,
|
|
fontSize: FontSizes.s14,
|
|
fontFamily: GoogleFonts.poppins(
|
|
fontWeight: FontWeight.w500,
|
|
).fontFamily,
|
|
),
|
|
const VSpace(4),
|
|
FlowyText.regular(
|
|
subtitle,
|
|
overflow: TextOverflow.ellipsis,
|
|
fontSize: FontSizes.s12,
|
|
fontFamily: GoogleFonts.poppins(
|
|
fontWeight: FontWeight.w300,
|
|
).fontFamily,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (trailing != null) ...[
|
|
const HSpace(40),
|
|
trailing!,
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|