Skip to content

Commit

Permalink
Merge pull request #2354 from acterglobal/kumar/space-list-provider-o…
Browse files Browse the repository at this point in the history
…ptimisation

Space List and Dashboard Sections Optimisation
  • Loading branch information
gnunicorn authored Nov 13, 2024
2 parents aaa6ad9 + c1448f0 commit 2b8ac72
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 442 deletions.
12 changes: 10 additions & 2 deletions app/lib/features/events/widgets/event_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class EventListWidget extends ConsumerWidget {
final int? limit;
final bool showSectionHeader;
final VoidCallback? onClickSectionHeader;
final String? sectionHeaderTitle;
final bool? isShowSeeAllButton;
final bool showSectionBg;
final bool shrinkWrap;
final bool isShowSpaceName;
final Widget Function()? emptyStateBuilder;
Expand All @@ -26,6 +29,9 @@ class EventListWidget extends ConsumerWidget {
required this.listProvider,
this.showSectionHeader = false,
this.onClickSectionHeader,
this.sectionHeaderTitle,
this.isShowSeeAllButton,
this.showSectionBg = true,
this.shrinkWrap = true,
this.emptyStateBuilder,
});
Expand Down Expand Up @@ -75,8 +81,10 @@ class EventListWidget extends ConsumerWidget {
mainAxisSize: MainAxisSize.min,
children: [
SectionHeader(
title: L10n.of(context).events,
isShowSeeAllButton: count < eventList.length,
title: sectionHeaderTitle ?? L10n.of(context).events,
isShowSeeAllButton:
isShowSeeAllButton ?? count < eventList.length,
showSectionBg: showSectionBg,
onTapSeeAll: () => onClickSectionHeader == null
? null
: onClickSectionHeader!(),
Expand Down
140 changes: 23 additions & 117 deletions app/lib/features/home/pages/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ import 'dart:io';

import 'package:acter/common/providers/space_providers.dart';
import 'package:acter/common/themes/app_theme.dart';
import 'package:acter/common/themes/colors/color_scheme.dart';
import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
import 'package:acter/common/utils/routes.dart';
import 'package:acter/common/widgets/empty_state_widget.dart';
import 'package:acter/common/widgets/user_avatar.dart';
import 'package:acter/features/events/providers/event_providers.dart';
import 'package:acter/features/home/providers/client_providers.dart';
import 'package:acter/features/home/widgets/features_nav_widget.dart';
import 'package:acter/features/home/widgets/in_dashboard.dart';
import 'package:acter/features/home/widgets/my_events.dart';
import 'package:acter/features/home/widgets/my_spaces_section.dart';
import 'package:acter/features/home/widgets/my_tasks.dart';
import 'package:acter/features/main/providers/main_providers.dart';
import 'package:acter_avatar/acter_avatar.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk.dart';
import 'package:atlas_icons/atlas_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand All @@ -30,7 +29,6 @@ class Dashboard extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final client = ref.watch(alwaysClientProvider);
final hasSpaces = ref.watch(hasSpacesProvider);
return InDashboard(
child: SafeArea(
bottom: false,
Expand All @@ -41,34 +39,7 @@ class Dashboard extends ConsumerWidget {
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
appBar: _buildDashboardAppBar(context, client),
floatingActionButton: manageQuickAddButton(context, ref),
body: Padding(
padding: const EdgeInsets.only(
top: 20,
left: 20,
right: 20,
),
child: SingleChildScrollView(
child: hasSpaces
? Column(
children: [
featuresNav(context),
const SizedBox(height: 20),
const MyEventsSection(
eventFilters: EventFilters.ongoing,
),
const SizedBox(height: 12),
const MyTasksSection(limit: 5),
const SizedBox(height: 20),
const MyEventsSection(
limit: 3,
eventFilters: EventFilters.upcoming,
),
const MySpacesSection(limit: 5),
],
)
: emptyState(context),
),
),
body: _buildDashboardBodyUI(context, ref),
),
),
);
Expand Down Expand Up @@ -106,92 +77,6 @@ class Dashboard extends ConsumerWidget {
);
}

Widget featuresNav(BuildContext context) {
final lang = L10n.of(context);
return Column(
children: [
const SizedBox(height: 20),
Row(
children: [
featuresNavItem(
context: context,
title: lang.pins,
iconData: Atlas.pin,
color: pinFeatureColor,
onTap: () => context.pushNamed(Routes.pins.name),
),
const SizedBox(width: 20),
featuresNavItem(
context: context,
title: lang.events,
iconData: Atlas.calendar_dots,
color: eventFeatureColor,
onTap: () => context.pushNamed(Routes.calendarEvents.name),
),
],
),
const SizedBox(height: 20),
Row(
children: [
featuresNavItem(
context: context,
title: lang.tasks,
iconData: Atlas.list,
color: taskFeatureColor,
onTap: () => context.pushNamed(Routes.tasks.name),
),
const SizedBox(width: 20),
featuresNavItem(
context: context,
title: lang.boosts,
iconData: Atlas.megaphone_thin,
color: boastFeatureColor,
onTap: () => context.pushNamed(Routes.updateList.name),
),
],
),
],
);
}

Widget featuresNavItem({
required BuildContext context,
required String title,
required IconData iconData,
required Color color,
required Function()? onTap,
}) {
return Expanded(
child: InkWell(
onTap: onTap,
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.all(Radius.circular(16)),
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: color,
borderRadius: const BorderRadius.all(Radius.circular(100)),
),
child: Icon(
iconData,
size: 16,
),
),
const SizedBox(width: 8),
Text(title),
],
),
),
),
);
}

SlotLayout manageQuickAddButton(BuildContext context, WidgetRef ref) {
return SlotLayout(
config: <Breakpoint, SlotLayoutConfig>{
Expand Down Expand Up @@ -223,6 +108,27 @@ class Dashboard extends ConsumerWidget {
);
}

Widget _buildDashboardBodyUI(BuildContext context, WidgetRef ref) {
final hasSpaces = ref.watch(hasSpacesProvider);
return SingleChildScrollView(
child: hasSpaces
? const Column(
children: [
FeaturesNavWidget(),
SizedBox(height: 12),
MyEventsSection(eventFilters: EventFilters.ongoing),
MyTasksSection(limit: 5),
MyEventsSection(
limit: 3,
eventFilters: EventFilters.upcoming,
),
MySpacesSection(limit: 5),
],
)
: emptyState(context),
);
}

Widget emptyState(BuildContext context) {
final lang = L10n.of(context);
return Center(
Expand Down
100 changes: 100 additions & 0 deletions app/lib/features/home/widgets/features_nav_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import 'package:acter/common/themes/colors/color_scheme.dart';
import 'package:acter/common/utils/routes.dart';
import 'package:atlas_icons/atlas_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';

class FeaturesNavWidget extends StatelessWidget {
const FeaturesNavWidget({super.key});

@override
Widget build(BuildContext context) {
final lang = L10n.of(context);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
const SizedBox(height: 20),
Row(
children: [
featuresNavItem(
context: context,
title: lang.pins,
iconData: Atlas.pin,
color: pinFeatureColor,
onTap: () => context.pushNamed(Routes.pins.name),
),
const SizedBox(width: 20),
featuresNavItem(
context: context,
title: lang.events,
iconData: Atlas.calendar_dots,
color: eventFeatureColor,
onTap: () => context.pushNamed(Routes.calendarEvents.name),
),
],
),
const SizedBox(height: 20),
Row(
children: [
featuresNavItem(
context: context,
title: lang.tasks,
iconData: Atlas.list,
color: taskFeatureColor,
onTap: () => context.pushNamed(Routes.tasks.name),
),
const SizedBox(width: 20),
featuresNavItem(
context: context,
title: lang.boosts,
iconData: Atlas.megaphone_thin,
color: boastFeatureColor,
onTap: () => context.pushNamed(Routes.updateList.name),
),
],
),
],
),
);
}

Widget featuresNavItem({
required BuildContext context,
required String title,
required IconData iconData,
required Color color,
required Function()? onTap,
}) {
return Expanded(
child: InkWell(
onTap: onTap,
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.all(Radius.circular(16)),
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: color,
borderRadius: const BorderRadius.all(Radius.circular(100)),
),
child: Icon(
iconData,
size: 16,
),
),
const SizedBox(width: 8),
Text(title),
],
),
),
),
);
}
}
Loading

0 comments on commit 2b8ac72

Please sign in to comment.