mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: move plugin application and presentation together
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
export 'trash_bloc.dart';
|
||||
export 'trash_listener.dart';
|
||||
export 'trash_service.dart';
|
@ -0,0 +1,92 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:app_flowy/plugins/trash/application/trash_service.dart';
|
||||
import 'package:app_flowy/plugins/trash/application/trash_listener.dart';
|
||||
|
||||
part 'trash_bloc.freezed.dart';
|
||||
|
||||
class TrashBloc extends Bloc<TrashEvent, TrashState> {
|
||||
final TrashService service;
|
||||
final TrashListener listener;
|
||||
TrashBloc({required this.service, required this.listener})
|
||||
: super(TrashState.init()) {
|
||||
on<TrashEvent>((event, emit) async {
|
||||
await event.map(initial: (e) async {
|
||||
listener.start(trashUpdated: _listenTrashUpdated);
|
||||
final result = await service.readTrash();
|
||||
emit(result.fold(
|
||||
(object) => state.copyWith(
|
||||
objects: object.items, successOrFailure: left(unit)),
|
||||
(error) => state.copyWith(successOrFailure: right(error)),
|
||||
));
|
||||
}, didReceiveTrash: (e) async {
|
||||
emit(state.copyWith(objects: e.trash));
|
||||
}, putback: (e) async {
|
||||
final result = await service.putback(e.trashId);
|
||||
await _handleResult(result, emit);
|
||||
}, delete: (e) async {
|
||||
final result =
|
||||
await service.deleteViews([Tuple2(e.trash.id, e.trash.ty)]);
|
||||
await _handleResult(result, emit);
|
||||
}, deleteAll: (e) async {
|
||||
final result = await service.deleteAll();
|
||||
await _handleResult(result, emit);
|
||||
}, restoreAll: (e) async {
|
||||
final result = await service.restoreAll();
|
||||
await _handleResult(result, emit);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _handleResult(
|
||||
Either<dynamic, FlowyError> result, Emitter<TrashState> emit) async {
|
||||
emit(result.fold(
|
||||
(l) => state.copyWith(successOrFailure: left(unit)),
|
||||
(error) => state.copyWith(successOrFailure: right(error)),
|
||||
));
|
||||
}
|
||||
|
||||
void _listenTrashUpdated(Either<List<TrashPB>, FlowyError> trashOrFailed) {
|
||||
trashOrFailed.fold(
|
||||
(trash) {
|
||||
add(TrashEvent.didReceiveTrash(trash));
|
||||
},
|
||||
(error) {
|
||||
Log.error(error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await listener.close();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
class TrashEvent with _$TrashEvent {
|
||||
const factory TrashEvent.initial() = Initial;
|
||||
const factory TrashEvent.didReceiveTrash(List<TrashPB> trash) = ReceiveTrash;
|
||||
const factory TrashEvent.putback(String trashId) = Putback;
|
||||
const factory TrashEvent.delete(TrashPB trash) = Delete;
|
||||
const factory TrashEvent.restoreAll() = RestoreAll;
|
||||
const factory TrashEvent.deleteAll() = DeleteAll;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class TrashState with _$TrashState {
|
||||
const factory TrashState({
|
||||
required List<TrashPB> objects,
|
||||
required Either<Unit, FlowyError> successOrFailure,
|
||||
}) = _TrashState;
|
||||
|
||||
factory TrashState.init() => TrashState(
|
||||
objects: [],
|
||||
successOrFailure: left(unit),
|
||||
);
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/folder_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart';
|
||||
import 'package:flowy_sdk/rust_stream.dart';
|
||||
|
||||
typedef TrashUpdatedCallback = void Function(Either<List<TrashPB>, FlowyError> trashOrFailed);
|
||||
|
||||
class TrashListener {
|
||||
StreamSubscription<SubscribeObject>? _subscription;
|
||||
TrashUpdatedCallback? _trashUpdated;
|
||||
FolderNotificationParser? _parser;
|
||||
|
||||
void start({TrashUpdatedCallback? trashUpdated}) {
|
||||
_trashUpdated = trashUpdated;
|
||||
_parser = FolderNotificationParser(callback: _bservableCallback);
|
||||
_subscription = RustStreamReceiver.listen((observable) => _parser?.parse(observable));
|
||||
}
|
||||
|
||||
void _bservableCallback(FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
||||
switch (ty) {
|
||||
case FolderNotification.TrashUpdated:
|
||||
if (_trashUpdated != null) {
|
||||
result.fold(
|
||||
(payload) {
|
||||
final repeatedTrash = RepeatedTrashPB.fromBuffer(payload);
|
||||
_trashUpdated!(left(repeatedTrash.items));
|
||||
},
|
||||
(error) => _trashUpdated!(right(error)),
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> close() async {
|
||||
_parser = null;
|
||||
await _subscription?.cancel();
|
||||
_trashUpdated = null;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
import 'dart:async';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart';
|
||||
|
||||
class TrashService {
|
||||
Future<Either<RepeatedTrashPB, FlowyError>> readTrash() {
|
||||
return FolderEventReadTrash().send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> putback(String trashId) {
|
||||
final id = TrashIdPB.create()..id = trashId;
|
||||
|
||||
return FolderEventPutbackTrash(id).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> deleteViews(List<Tuple2<String, TrashType>> trashList) {
|
||||
final items = trashList.map((trash) {
|
||||
return TrashIdPB.create()
|
||||
..id = trash.value1
|
||||
..ty = trash.value2;
|
||||
});
|
||||
|
||||
final ids = RepeatedTrashIdPB(items: items);
|
||||
return FolderEventDeleteTrash(ids).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> restoreAll() {
|
||||
return FolderEventRestoreAllTrash().send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> deleteAll() {
|
||||
return FolderEventDeleteAllTrash().send();
|
||||
}
|
||||
}
|
56
frontend/app_flowy/lib/plugins/trash/menu.dart
Normal file
56
frontend/app_flowy/lib/plugins/trash/menu.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:app_flowy/startup/plugin/plugin.dart';
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/workspace/application/appearance.dart';
|
||||
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
|
||||
import 'package:app_flowy/workspace/presentation/home/menu/menu.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/image.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
|
||||
class MenuTrash extends StatelessWidget {
|
||||
const MenuTrash({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 26,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
getIt<MenuSharedState>().latestOpenView = null;
|
||||
getIt<HomeStackManager>()
|
||||
.setPlugin(makePlugin(pluginType: DefaultPlugin.trash.type()));
|
||||
},
|
||||
child: _render(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _render(BuildContext context) {
|
||||
return Row(children: [
|
||||
ChangeNotifierProvider.value(
|
||||
value: Provider.of<AppearanceSettingModel>(context, listen: true),
|
||||
child: Selector<AppearanceSettingModel, AppTheme>(
|
||||
selector: (ctx, notifier) => notifier.theme,
|
||||
builder: (ctx, theme, child) => SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: svgWidget("home/trash", color: theme.iconColor)),
|
||||
),
|
||||
),
|
||||
const HSpace(6),
|
||||
ChangeNotifierProvider.value(
|
||||
value: Provider.of<AppearanceSettingModel>(context, listen: true),
|
||||
child: Selector<AppearanceSettingModel, Locale>(
|
||||
selector: (ctx, notifier) => notifier.locale,
|
||||
builder: (ctx, _, child) =>
|
||||
FlowyText.medium(LocaleKeys.trash_text.tr(), fontSize: 12),
|
||||
),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
10
frontend/app_flowy/lib/plugins/trash/src/sizes.dart
Normal file
10
frontend/app_flowy/lib/plugins/trash/src/sizes.dart
Normal file
@ -0,0 +1,10 @@
|
||||
class TrashSizes {
|
||||
static double scale = 0.8;
|
||||
static double get headerHeight => 60 * scale;
|
||||
static double get fileNameWidth => 320 * scale;
|
||||
static double get lashModifyWidth => 230 * scale;
|
||||
static double get createTimeWidth => 230 * scale;
|
||||
static double get padding => 100 * scale;
|
||||
static double get totalWidth =>
|
||||
TrashSizes.fileNameWidth + TrashSizes.lashModifyWidth + TrashSizes.createTimeWidth + TrashSizes.padding;
|
||||
}
|
50
frontend/app_flowy/lib/plugins/trash/src/trash_cell.dart
Normal file
50
frontend/app_flowy/lib/plugins/trash/src/trash_cell.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:flowy_infra/image.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:fixnum/fixnum.dart' as $fixnum;
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'sizes.dart';
|
||||
|
||||
class TrashCell extends StatelessWidget {
|
||||
final VoidCallback onRestore;
|
||||
final VoidCallback onDelete;
|
||||
final TrashPB object;
|
||||
const TrashCell({required this.object, required this.onRestore, required this.onDelete, Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = context.watch<AppTheme>();
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(width: TrashSizes.fileNameWidth, child: FlowyText(object.name, fontSize: 12)),
|
||||
SizedBox(width: TrashSizes.lashModifyWidth, child: FlowyText(dateFormatter(object.modifiedTime), fontSize: 12)),
|
||||
SizedBox(width: TrashSizes.createTimeWidth, child: FlowyText(dateFormatter(object.createTime), fontSize: 12)),
|
||||
const Spacer(),
|
||||
FlowyIconButton(
|
||||
width: 16,
|
||||
onPressed: onRestore,
|
||||
icon: svgWidget("editor/restore", color: theme.iconColor),
|
||||
),
|
||||
const HSpace(20),
|
||||
FlowyIconButton(
|
||||
width: 16,
|
||||
onPressed: onDelete,
|
||||
icon: svgWidget("editor/delete", color: theme.iconColor),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String dateFormatter($fixnum.Int64 inputTimestamps) {
|
||||
var outputFormat = DateFormat('MM/dd/yyyy hh:mm a');
|
||||
var date = DateTime.fromMillisecondsSinceEpoch(inputTimestamps.toInt() * 1000);
|
||||
var outputDate = outputFormat.format(date);
|
||||
return outputDate;
|
||||
}
|
||||
}
|
73
frontend/app_flowy/lib/plugins/trash/src/trash_header.dart
Normal file
73
frontend/app_flowy/lib/plugins/trash/src/trash_header.dart
Normal file
@ -0,0 +1,73 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
|
||||
import 'sizes.dart';
|
||||
|
||||
class TrashHeaderDelegate extends SliverPersistentHeaderDelegate {
|
||||
TrashHeaderDelegate();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
|
||||
return TrashHeader();
|
||||
}
|
||||
|
||||
@override
|
||||
double get maxExtent => TrashSizes.headerHeight;
|
||||
|
||||
@override
|
||||
double get minExtent => TrashSizes.headerHeight;
|
||||
|
||||
@override
|
||||
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class TrashHeaderItem {
|
||||
double width;
|
||||
String title;
|
||||
|
||||
TrashHeaderItem({required this.width, required this.title});
|
||||
}
|
||||
|
||||
class TrashHeader extends StatelessWidget {
|
||||
final List<TrashHeaderItem> items = [
|
||||
TrashHeaderItem(title: LocaleKeys.trash_pageHeader_fileName.tr(), width: TrashSizes.fileNameWidth),
|
||||
TrashHeaderItem(title: LocaleKeys.trash_pageHeader_lastModified.tr(), width: TrashSizes.lashModifyWidth),
|
||||
TrashHeaderItem(title: LocaleKeys.trash_pageHeader_created.tr(), width: TrashSizes.createTimeWidth),
|
||||
];
|
||||
|
||||
TrashHeader({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = context.watch<AppTheme>();
|
||||
final headerItems = List<Widget>.empty(growable: true);
|
||||
items.asMap().forEach((index, item) {
|
||||
headerItems.add(
|
||||
SizedBox(
|
||||
width: item.width,
|
||||
child: FlowyText(
|
||||
item.title,
|
||||
fontSize: 12,
|
||||
color: theme.shader3,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
return Container(
|
||||
color: theme.surface,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
...headerItems,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
215
frontend/app_flowy/lib/plugins/trash/trash.dart
Normal file
215
frontend/app_flowy/lib/plugins/trash/trash.dart
Normal file
@ -0,0 +1,215 @@
|
||||
export "./src/sizes.dart";
|
||||
export "./src/trash_cell.dart";
|
||||
export "./src/trash_header.dart";
|
||||
|
||||
import 'package:app_flowy/startup/plugin/plugin.dart';
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/plugins/trash/application/trash_bloc.dart';
|
||||
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/image.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
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';
|
||||
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';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
|
||||
import 'src/sizes.dart';
|
||||
import 'src/trash_cell.dart';
|
||||
import 'src/trash_header.dart';
|
||||
|
||||
class TrashPluginBuilder extends PluginBuilder {
|
||||
@override
|
||||
Plugin build(dynamic data) {
|
||||
return TrashPlugin(pluginType: pluginType);
|
||||
}
|
||||
|
||||
@override
|
||||
String get menuName => "TrashPB";
|
||||
|
||||
@override
|
||||
PluginType get pluginType => DefaultPlugin.trash.type();
|
||||
}
|
||||
|
||||
class TrashPluginConfig implements PluginConfig {
|
||||
@override
|
||||
bool get creatable => false;
|
||||
}
|
||||
|
||||
class TrashPlugin extends Plugin {
|
||||
final PluginType _pluginType;
|
||||
|
||||
TrashPlugin({required PluginType pluginType}) : _pluginType = pluginType;
|
||||
|
||||
@override
|
||||
PluginDisplay get display => TrashPluginDisplay();
|
||||
|
||||
@override
|
||||
PluginId get id => "TrashStack";
|
||||
|
||||
@override
|
||||
PluginType get ty => _pluginType;
|
||||
}
|
||||
|
||||
class TrashPluginDisplay extends PluginDisplay {
|
||||
@override
|
||||
Widget get leftBarItem =>
|
||||
FlowyText.medium(LocaleKeys.trash_text.tr(), fontSize: 12);
|
||||
|
||||
@override
|
||||
Widget? get rightBarItem => null;
|
||||
|
||||
@override
|
||||
Widget buildWidget() => const TrashPage(key: ValueKey('TrashPage'));
|
||||
|
||||
@override
|
||||
List<NavigationItem> get navigationItems => [this];
|
||||
}
|
||||
|
||||
class TrashPage extends StatefulWidget {
|
||||
const TrashPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<TrashPage> createState() => _TrashPageState();
|
||||
}
|
||||
|
||||
class _TrashPageState extends State<TrashPage> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = context.watch<AppTheme>();
|
||||
const horizontalPadding = 80.0;
|
||||
return BlocProvider(
|
||||
create: (context) => getIt<TrashBloc>()..add(const TrashEvent.initial()),
|
||||
child: BlocBuilder<TrashBloc, TrashState>(
|
||||
builder: (context, state) {
|
||||
return SizedBox.expand(
|
||||
child: Column(
|
||||
children: [
|
||||
_renderTopBar(context, theme, state),
|
||||
const VSpace(32),
|
||||
_renderTrashList(context, state),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
).padding(horizontal: horizontalPadding, vertical: 48),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _renderTrashList(BuildContext context, TrashState state) {
|
||||
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(),
|
||||
barSize: barSize,
|
||||
axis: Axis.horizontal,
|
||||
child: SizedBox(
|
||||
width: TrashSizes.totalWidth,
|
||||
child: ScrollConfiguration(
|
||||
behavior: const ScrollBehavior().copyWith(scrollbars: false),
|
||||
child: CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
physics: StyledScrollPhysics(),
|
||||
controller: _scrollController,
|
||||
slivers: [
|
||||
_renderListHeader(context, state),
|
||||
_renderListBody(context, state),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _renderTopBar(BuildContext context, AppTheme theme, TrashState state) {
|
||||
return SizedBox(
|
||||
height: 36,
|
||||
child: Row(
|
||||
children: [
|
||||
FlowyText.semibold(LocaleKeys.trash_text.tr()),
|
||||
const Spacer(),
|
||||
SizedBox.fromSize(
|
||||
size: const Size(102, 30),
|
||||
child: FlowyButton(
|
||||
text: FlowyText.medium(LocaleKeys.trash_restoreAll.tr(),
|
||||
fontSize: 12),
|
||||
leftIcon: svgWidget('editor/restore', color: theme.iconColor),
|
||||
hoverColor: theme.hover,
|
||||
onTap: () =>
|
||||
context.read<TrashBloc>().add(const TrashEvent.restoreAll()),
|
||||
),
|
||||
),
|
||||
const HSpace(6),
|
||||
SizedBox.fromSize(
|
||||
size: const Size(102, 30),
|
||||
child: FlowyButton(
|
||||
text: FlowyText.medium(LocaleKeys.trash_deleteAll.tr(),
|
||||
fontSize: 12),
|
||||
leftIcon: svgWidget('editor/delete', color: theme.iconColor),
|
||||
hoverColor: theme.hover,
|
||||
onTap: () =>
|
||||
context.read<TrashBloc>().add(const TrashEvent.deleteAll()),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _renderListHeader(BuildContext context, TrashState state) {
|
||||
return SliverPersistentHeader(
|
||||
delegate: TrashHeaderDelegate(),
|
||||
floating: true,
|
||||
pinned: true,
|
||||
);
|
||||
}
|
||||
|
||||
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));
|
||||
},
|
||||
onDelete: () =>
|
||||
context.read<TrashBloc>().add(TrashEvent.delete(object)),
|
||||
),
|
||||
);
|
||||
},
|
||||
childCount: state.objects.length,
|
||||
addAutomaticKeepAlives: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
// 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,
|
||||
// );
|
||||
// }
|
||||
// }
|
Reference in New Issue
Block a user