2022-03-01 08:05:45 +00:00
|
|
|
export "./src/sizes.dart";
|
|
|
|
export "./src/trash_cell.dart";
|
|
|
|
export "./src/trash_header.dart";
|
|
|
|
|
2022-08-09 02:35:27 +00:00
|
|
|
import 'package:app_flowy/startup/plugin/plugin.dart';
|
2021-10-14 06:34:22 +00:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
2022-08-09 02:35:27 +00:00
|
|
|
import 'package:app_flowy/plugins/trash/application/trash_bloc.dart';
|
2022-03-01 08:05:45 +00:00
|
|
|
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
|
2021-12-07 17:31:23 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-10-13 15:11:45 +00:00
|
|
|
import 'package:flowy_infra/image.dart';
|
|
|
|
import 'package:flowy_infra/theme.dart';
|
2021-10-14 10:11:59 +00:00
|
|
|
import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart';
|
|
|
|
import 'package:flowy_infra_ui/style_widget/scrolling/styled_scroll_bar.dart';
|
|
|
|
import 'package:flowy_infra_ui/style_widget/scrolling/styled_scrollview.dart';
|
2021-10-13 15:11:45 +00:00
|
|
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
|
|
|
import 'package:flowy_infra_ui/style_widget/button.dart';
|
|
|
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2021-10-14 06:34:22 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2021-10-13 15:11:45 +00:00
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
2021-12-07 17:31:23 +00:00
|
|
|
import 'package:app_flowy/generated/locale_keys.g.dart';
|
2021-10-13 15:11:45 +00:00
|
|
|
|
2022-03-01 08:05:45 +00:00
|
|
|
import 'src/sizes.dart';
|
|
|
|
import 'src/trash_cell.dart';
|
|
|
|
import 'src/trash_header.dart';
|
2021-10-14 06:34:22 +00:00
|
|
|
|
2022-03-01 02:25:21 +00:00
|
|
|
class TrashPluginBuilder extends PluginBuilder {
|
2022-02-28 14:38:53 +00:00
|
|
|
@override
|
|
|
|
Plugin build(dynamic data) {
|
|
|
|
return TrashPlugin(pluginType: pluginType);
|
|
|
|
}
|
2021-10-13 15:11:45 +00:00
|
|
|
|
|
|
|
@override
|
2022-07-19 06:11:29 +00:00
|
|
|
String get menuName => "TrashPB";
|
2021-10-13 15:11:45 +00:00
|
|
|
|
|
|
|
@override
|
2022-08-18 11:32:08 +00:00
|
|
|
PluginType get pluginType => PluginType.trash;
|
2022-02-28 14:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 03:22:39 +00:00
|
|
|
class TrashPluginConfig implements PluginConfig {
|
|
|
|
@override
|
|
|
|
bool get creatable => false;
|
|
|
|
}
|
|
|
|
|
2022-03-01 08:05:45 +00:00
|
|
|
class TrashPlugin extends Plugin {
|
2022-03-01 02:25:21 +00:00
|
|
|
final PluginType _pluginType;
|
2022-02-28 14:38:53 +00:00
|
|
|
|
2022-03-01 02:25:21 +00:00
|
|
|
TrashPlugin({required PluginType pluginType}) : _pluginType = pluginType;
|
2021-11-09 15:13:04 +00:00
|
|
|
|
2021-10-13 15:11:45 +00:00
|
|
|
@override
|
2022-03-02 03:38:22 +00:00
|
|
|
PluginDisplay get display => TrashPluginDisplay();
|
2021-10-13 15:11:45 +00:00
|
|
|
|
|
|
|
@override
|
2022-03-02 03:38:22 +00:00
|
|
|
PluginId get id => "TrashStack";
|
2021-10-13 15:11:45 +00:00
|
|
|
|
2021-10-28 13:55:22 +00:00
|
|
|
@override
|
2022-03-02 03:38:22 +00:00
|
|
|
PluginType get ty => _pluginType;
|
2022-02-28 14:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class TrashPluginDisplay extends PluginDisplay {
|
|
|
|
@override
|
2022-08-09 02:35:27 +00:00
|
|
|
Widget get leftBarItem =>
|
|
|
|
FlowyText.medium(LocaleKeys.trash_text.tr(), fontSize: 12);
|
2022-02-28 14:38:53 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget? get rightBarItem => null;
|
|
|
|
|
|
|
|
@override
|
2022-03-04 00:22:49 +00:00
|
|
|
Widget buildWidget() => const TrashPage(key: ValueKey('TrashPage'));
|
2022-02-28 14:38:53 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<NavigationItem> get navigationItems => [this];
|
2021-10-13 15:11:45 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 00:22:49 +00:00
|
|
|
class TrashPage extends StatefulWidget {
|
|
|
|
const TrashPage({Key? key}) : super(key: key);
|
2021-10-13 15:11:45 +00:00
|
|
|
|
|
|
|
@override
|
2022-03-04 00:22:49 +00:00
|
|
|
State<TrashPage> createState() => _TrashPageState();
|
2021-10-13 15:11:45 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 00:22:49 +00:00
|
|
|
class _TrashPageState extends State<TrashPage> {
|
2021-10-14 10:11:59 +00:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
2021-10-13 15:11:45 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = context.watch<AppTheme>();
|
2021-10-14 14:58:20 +00:00
|
|
|
const horizontalPadding = 80.0;
|
2021-10-18 10:40:15 +00:00
|
|
|
return BlocProvider(
|
|
|
|
create: (context) => getIt<TrashBloc>()..add(const TrashEvent.initial()),
|
|
|
|
child: BlocBuilder<TrashBloc, TrashState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
return SizedBox.expand(
|
|
|
|
child: Column(
|
2022-08-31 01:19:31 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
2021-10-18 10:40:15 +00:00
|
|
|
children: [
|
|
|
|
_renderTopBar(context, theme, state),
|
|
|
|
const VSpace(32),
|
|
|
|
_renderTrashList(context, state),
|
|
|
|
],
|
|
|
|
).padding(horizontal: horizontalPadding, vertical: 48),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2021-10-14 14:58:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:40:15 +00:00
|
|
|
Widget _renderTrashList(BuildContext context, TrashState state) {
|
2021-10-14 14:58:20 +00:00
|
|
|
const barSize = 6.0;
|
|
|
|
return Expanded(
|
|
|
|
child: ScrollbarListStack(
|
|
|
|
axis: Axis.vertical,
|
|
|
|
controller: _scrollController,
|
|
|
|
scrollbarPadding: EdgeInsets.only(top: TrashSizes.headerHeight),
|
|
|
|
barSize: barSize,
|
|
|
|
child: StyledSingleChildScrollView(
|
|
|
|
controller: ScrollController(),
|
2021-10-28 07:22:18 +00:00
|
|
|
barSize: barSize,
|
2021-10-14 14:58:20 +00:00
|
|
|
axis: Axis.horizontal,
|
|
|
|
child: SizedBox(
|
|
|
|
width: TrashSizes.totalWidth,
|
2021-10-15 05:10:52 +00:00
|
|
|
child: ScrollConfiguration(
|
|
|
|
behavior: const ScrollBehavior().copyWith(scrollbars: false),
|
|
|
|
child: CustomScrollView(
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: StyledScrollPhysics(),
|
|
|
|
controller: _scrollController,
|
|
|
|
slivers: [
|
2021-10-18 10:40:15 +00:00
|
|
|
_renderListHeader(context, state),
|
|
|
|
_renderListBody(context, state),
|
2021-10-15 05:10:52 +00:00
|
|
|
],
|
|
|
|
),
|
2021-10-14 06:34:22 +00:00
|
|
|
),
|
|
|
|
),
|
2021-10-14 14:58:20 +00:00
|
|
|
),
|
|
|
|
),
|
2021-10-13 15:11:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:40:15 +00:00
|
|
|
Widget _renderTopBar(BuildContext context, AppTheme theme, TrashState state) {
|
2021-10-13 15:11:45 +00:00
|
|
|
return SizedBox(
|
|
|
|
height: 36,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2021-12-07 17:31:23 +00:00
|
|
|
FlowyText.semibold(LocaleKeys.trash_text.tr()),
|
2021-10-13 15:11:45 +00:00
|
|
|
const Spacer(),
|
|
|
|
SizedBox.fromSize(
|
|
|
|
size: const Size(102, 30),
|
|
|
|
child: FlowyButton(
|
2022-08-09 02:35:27 +00:00
|
|
|
text: FlowyText.medium(LocaleKeys.trash_restoreAll.tr(),
|
|
|
|
fontSize: 12),
|
2022-04-03 02:53:24 +00:00
|
|
|
leftIcon: svgWidget('editor/restore', color: theme.iconColor),
|
2021-10-13 15:11:45 +00:00
|
|
|
hoverColor: theme.hover,
|
2022-08-09 02:35:27 +00:00
|
|
|
onTap: () =>
|
|
|
|
context.read<TrashBloc>().add(const TrashEvent.restoreAll()),
|
2021-10-13 15:11:45 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const HSpace(6),
|
|
|
|
SizedBox.fromSize(
|
|
|
|
size: const Size(102, 30),
|
|
|
|
child: FlowyButton(
|
2022-08-09 02:35:27 +00:00
|
|
|
text: FlowyText.medium(LocaleKeys.trash_deleteAll.tr(),
|
|
|
|
fontSize: 12),
|
2022-04-03 02:53:24 +00:00
|
|
|
leftIcon: svgWidget('editor/delete', color: theme.iconColor),
|
2021-10-13 15:11:45 +00:00
|
|
|
hoverColor: theme.hover,
|
2022-08-09 02:35:27 +00:00
|
|
|
onTap: () =>
|
|
|
|
context.read<TrashBloc>().add(const TrashEvent.deleteAll()),
|
2021-10-13 15:11:45 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:40:15 +00:00
|
|
|
Widget _renderListHeader(BuildContext context, TrashState state) {
|
2021-10-14 06:34:22 +00:00
|
|
|
return SliverPersistentHeader(
|
|
|
|
delegate: TrashHeaderDelegate(),
|
2021-10-13 15:11:45 +00:00
|
|
|
floating: true,
|
2021-10-14 06:34:22 +00:00
|
|
|
pinned: true,
|
2021-10-13 15:11:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:40:15 +00:00
|
|
|
Widget _renderListBody(BuildContext context, TrashState state) {
|
|
|
|
return SliverList(
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
final object = state.objects[index];
|
|
|
|
return SizedBox(
|
|
|
|
height: 42,
|
|
|
|
child: TrashCell(
|
|
|
|
object: object,
|
|
|
|
onRestore: () {
|
|
|
|
context.read<TrashBloc>().add(TrashEvent.putback(object.id));
|
2021-10-14 06:34:22 +00:00
|
|
|
},
|
2022-08-09 02:35:27 +00:00
|
|
|
onDelete: () =>
|
|
|
|
context.read<TrashBloc>().add(TrashEvent.delete(object)),
|
2021-10-13 15:11:45 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2021-10-18 10:40:15 +00:00
|
|
|
childCount: state.objects.length,
|
|
|
|
addAutomaticKeepAlives: false,
|
2021-10-13 15:11:45 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-10-15 05:10:52 +00:00
|
|
|
// class TrashScrollbar extends ScrollBehavior {
|
|
|
|
// @override
|
|
|
|
// Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) {
|
|
|
|
// return ScrollbarListStack(
|
|
|
|
// controller: details.controller,
|
|
|
|
// axis: Axis.vertical,
|
|
|
|
// barSize: 6,
|
|
|
|
// child: child,
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// }
|