refactor: remove unused code

This commit is contained in:
gaganyadav80 2022-03-24 15:49:53 +05:30
parent 8ab2fe3e30
commit 933689269b
2 changed files with 30 additions and 56 deletions

View File

@ -12,17 +12,10 @@ import 'package:styled_widget/styled_widget.dart';
import 'item.dart'; import 'item.dart';
import 'package:async/async.dart'; import 'package:async/async.dart';
//? @gaganyadav80: Build 3 times on startup. Then one time on each doc change. class ViewSection extends StatelessWidget {
class ViewSection extends StatefulWidget {
final AppDataNotifier appData; final AppDataNotifier appData;
const ViewSection({Key? key, required this.appData}) : super(key: key); const ViewSection({Key? key, required this.appData}) : super(key: key);
@override
State<ViewSection> createState() => _ViewSectionState();
}
class _ViewSectionState extends State<ViewSection> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// The ViewSectionNotifier will be updated after AppDataNotifier changed passed by parent widget // The ViewSectionNotifier will be updated after AppDataNotifier changed passed by parent widget
@ -30,20 +23,43 @@ class _ViewSectionState extends State<ViewSection> {
create: (_) { create: (_) {
return ViewSectionNotifier( return ViewSectionNotifier(
context: context, context: context,
views: widget.appData.views, views: appData.views,
initialSelectedView: widget.appData.selectedView, initialSelectedView: appData.selectedView,
); );
}, },
update: (_, notifier, controller) => controller!..update(notifier), update: (_, notifier, controller) => controller!..update(notifier),
child: Consumer(builder: (context, ViewSectionNotifier notifier, child) { child: Consumer(builder: (context, ViewSectionNotifier notifier, child) {
log("BUILD: Section Bloc section update triggered + ${notifier.views.length}");
return RenderSectionItems(views: notifier.views); return RenderSectionItems(views: notifier.views);
}), }),
); );
} }
// Widget _renderSectionItems(BuildContext context, List<View> views) { // Widget _renderSectionItems(BuildContext context, List<View> views) {
// return Container(); // List<Widget> viewWidgets = [];
// if (views.isNotEmpty) {
// viewWidgets = views
// .map(
// (view) => ViewSectionItem(
// view: view,
// isSelected: _isViewSelected(context, view.id),
// onSelected: (view) {
// context.read<ViewSectionNotifier>().selectedView = view;
// Provider.of<MenuSharedState>(context, listen: false).selectedView.value = view;
// },
// ).padding(vertical: 4),
// )
// .toList(growable: false);
// }
// return Column(children: viewWidgets);
// }
// bool _isViewSelected(BuildContext context, String viewId) {
// final view = context.read<ViewSectionNotifier>().selectedView;
// if (view == null) {
// return false;
// }
// return view.id == viewId;
// } // }
} }
@ -57,8 +73,6 @@ class RenderSectionItems extends StatefulWidget {
} }
class _RenderSectionItemsState extends State<RenderSectionItems> { class _RenderSectionItemsState extends State<RenderSectionItems> {
// List<Widget> viewWidgets = List.empty(growable: true);
// List<Widget> sectionItems = List.empty(growable: true);
List<View> views = <View>[]; List<View> views = <View>[];
/// Maps the hasmap value of the section items to their index in the reorderable list. /// Maps the hasmap value of the section items to their index in the reorderable list.
@ -67,30 +81,11 @@ class _RenderSectionItemsState extends State<RenderSectionItems> {
void _initItemList() { void _initItemList() {
views.addAll(widget.views); views.addAll(widget.views);
// log(widget.views.length.toString());
// if (widget.views.isNotEmpty) {
// viewWidgets = widget.views
// .map(
// (view) => ViewSectionItem(
// view: view,
// isSelected: _isViewSelected(context, view.id),
// onSelected: (view) {
// context.read<ViewSectionNotifier>().selectedView = view;
// Provider.of<MenuSharedState>(context, listen: false).selectedView.value = view;
// },
// ).padding(vertical: 4),
// )
// .toList(growable: false);
// }
// sectionItems.clear();
for (int i = 0; i < views.length; i++) { for (int i = 0; i < views.length; i++) {
if (_sectionItemIndex[views[i].id] == null) { if (_sectionItemIndex[views[i].id] == null) {
_sectionItemIndex[views[i].id] = i; _sectionItemIndex[views[i].id] = i;
} }
// sectionItems.insert(_sectionItemIndex[viewWidgets[i].key.hashCode]!, viewWidgets[i]);
} }
} }
@ -108,8 +103,6 @@ class _RenderSectionItemsState extends State<RenderSectionItems> {
log("BUILD: Section items: ${views.length}"); log("BUILD: Section items: ${views.length}");
return ReorderableColumn( return ReorderableColumn(
// itemCount: sectionItems.length,
// buildDefaultDragHandles: false,
needsLongPressDraggable: false, needsLongPressDraggable: false,
onReorder: (oldIndex, index) { onReorder: (oldIndex, index) {
setState(() { setState(() {
@ -120,14 +113,11 @@ class _RenderSectionItemsState extends State<RenderSectionItems> {
_sectionItemIndex[section.id] = index; _sectionItemIndex[section.id] = index;
}); });
}, },
// physics: StyledScrollPhysics(),
// itemBuilder: (context, index) {},
children: List.generate( children: List.generate(
views.length, views.length,
(index) { (index) {
return Container( return Container(
key: ValueKey(views[index].id), key: ValueKey(views[index].id),
// index: index,
child: views child: views
.map( .map(
(view) => ViewSectionItem( (view) => ViewSectionItem(

View File

@ -1,8 +1,6 @@
export './app/header/header.dart'; export './app/header/header.dart';
export './app/menu_app.dart'; export './app/menu_app.dart';
import 'dart:developer';
import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
import 'package:app_flowy/workspace/presentation/plugins/trash/menu.dart'; import 'package:app_flowy/workspace/presentation/plugins/trash/menu.dart';
import 'package:flowy_infra/notifier.dart'; import 'package:flowy_infra/notifier.dart';
@ -47,9 +45,8 @@ class HomeMenu extends StatefulWidget {
} }
class _HomeMenuState extends State<HomeMenu> { class _HomeMenuState extends State<HomeMenu> {
// final List<Widget> _menuItems = List.empty(growable: true);
/// Maps the hashmap of the menu items to their index in reorderable list view. /// Maps the hashmap of the menu items to their index in reorderable list view.
//TODO @gaganyadav80: need to retain this to persist on app restarts. //TODO @gaganyadav80: Retain this map to persist on app restarts.
final Map<int, int> _menuItemIndex = <int, int>{}; final Map<int, int> _menuItemIndex = <int, int>{};
@override @override
@ -140,19 +137,6 @@ class _HomeMenuState extends State<HomeMenu> {
menuItems.insert(_menuItemIndex[appWidgets[i].key.hashCode]!, appWidgets[i]); menuItems.insert(_menuItemIndex[appWidgets[i].key.hashCode]!, appWidgets[i]);
} }
// for (var app in appWidgets) {
// if (!_menuItems.any((oldElement) => oldElement.key == app.key)) {
// _menuItems.add(app);
// }
// }
// // TODO @gaganyadav80: fix: concurrent modification exception
// // Unhandled Exception: Concurrent modification during iteration: Instance(length:3) of '_GrowableList'.
// for (var item in _menuItems) {
// if (!appWidgets.any((oldElement) => oldElement.key == item.key)) {
// _menuItems.remove(item);
// }
// }
return menuItems; return menuItems;
}, },
builder: (context, menuItems) { builder: (context, menuItems) {
@ -179,7 +163,7 @@ class _HomeMenuState extends State<HomeMenu> {
}, },
physics: StyledScrollPhysics(), physics: StyledScrollPhysics(),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
//? To mimic the ListView.separated behavior, we need to add a padding. //? @gaganyadav80: To mimic the ListView.separated behavior, we need to add a padding.
// EdgeInsets padding = EdgeInsets.zero; // EdgeInsets padding = EdgeInsets.zero;
// if (index == 0) { // if (index == 0) {
// padding = EdgeInsets.only(bottom: MenuAppSizes.appVPadding / 2); // padding = EdgeInsets.only(bottom: MenuAppSizes.appVPadding / 2);