From 933689269bb5a78c17914c75568883644f415451 Mon Sep 17 00:00:00 2001 From: gaganyadav80 Date: Thu, 24 Mar 2022 15:49:53 +0530 Subject: [PATCH] refactor: remove unused code --- .../home/menu/app/section/section.dart | 66 ++++++++----------- .../presentation/home/menu/menu.dart | 20 +----- 2 files changed, 30 insertions(+), 56 deletions(-) diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/section.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/section.dart index c0d82930b1..79f595a428 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/section.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/section.dart @@ -12,17 +12,10 @@ import 'package:styled_widget/styled_widget.dart'; import 'item.dart'; import 'package:async/async.dart'; -//? @gaganyadav80: Build 3 times on startup. Then one time on each doc change. - -class ViewSection extends StatefulWidget { +class ViewSection extends StatelessWidget { final AppDataNotifier appData; const ViewSection({Key? key, required this.appData}) : super(key: key); - @override - State createState() => _ViewSectionState(); -} - -class _ViewSectionState extends State { @override Widget build(BuildContext context) { // The ViewSectionNotifier will be updated after AppDataNotifier changed passed by parent widget @@ -30,20 +23,43 @@ class _ViewSectionState extends State { create: (_) { return ViewSectionNotifier( context: context, - views: widget.appData.views, - initialSelectedView: widget.appData.selectedView, + views: appData.views, + initialSelectedView: appData.selectedView, ); }, update: (_, notifier, controller) => controller!..update(notifier), child: Consumer(builder: (context, ViewSectionNotifier notifier, child) { - log("BUILD: Section Bloc section update triggered + ${notifier.views.length}"); return RenderSectionItems(views: notifier.views); }), ); } // Widget _renderSectionItems(BuildContext context, List views) { - // return Container(); + // List viewWidgets = []; + // if (views.isNotEmpty) { + // viewWidgets = views + // .map( + // (view) => ViewSectionItem( + // view: view, + // isSelected: _isViewSelected(context, view.id), + // onSelected: (view) { + // context.read().selectedView = view; + // Provider.of(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().selectedView; + // if (view == null) { + // return false; + // } + // return view.id == viewId; // } } @@ -57,8 +73,6 @@ class RenderSectionItems extends StatefulWidget { } class _RenderSectionItemsState extends State { - // List viewWidgets = List.empty(growable: true); - // List sectionItems = List.empty(growable: true); List views = []; /// Maps the hasmap value of the section items to their index in the reorderable list. @@ -67,30 +81,11 @@ class _RenderSectionItemsState extends State { void _initItemList() { 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().selectedView = view; - // Provider.of(context, listen: false).selectedView.value = view; - // }, - // ).padding(vertical: 4), - // ) - // .toList(growable: false); - // } - - // sectionItems.clear(); for (int i = 0; i < views.length; i++) { if (_sectionItemIndex[views[i].id] == null) { _sectionItemIndex[views[i].id] = i; } - - // sectionItems.insert(_sectionItemIndex[viewWidgets[i].key.hashCode]!, viewWidgets[i]); } } @@ -108,8 +103,6 @@ class _RenderSectionItemsState extends State { log("BUILD: Section items: ${views.length}"); return ReorderableColumn( - // itemCount: sectionItems.length, - // buildDefaultDragHandles: false, needsLongPressDraggable: false, onReorder: (oldIndex, index) { setState(() { @@ -120,14 +113,11 @@ class _RenderSectionItemsState extends State { _sectionItemIndex[section.id] = index; }); }, - // physics: StyledScrollPhysics(), - // itemBuilder: (context, index) {}, children: List.generate( views.length, (index) { return Container( key: ValueKey(views[index].id), - // index: index, child: views .map( (view) => ViewSectionItem( diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart index 99f3d22946..6db19495ac 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart @@ -1,8 +1,6 @@ export './app/header/header.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/plugins/trash/menu.dart'; import 'package:flowy_infra/notifier.dart'; @@ -47,9 +45,8 @@ class HomeMenu extends StatefulWidget { } class _HomeMenuState extends State { - // final List _menuItems = List.empty(growable: true); /// 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 _menuItemIndex = {}; @override @@ -140,19 +137,6 @@ class _HomeMenuState extends State { 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; }, builder: (context, menuItems) { @@ -179,7 +163,7 @@ class _HomeMenuState extends State { }, physics: StyledScrollPhysics(), 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; // if (index == 0) { // padding = EdgeInsets.only(bottom: MenuAppSizes.appVPadding / 2);