Skip to content

Commit

Permalink
auto sliding charts at home added to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Mar 24, 2024
1 parent bd46e33 commit 4842411
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
3 changes: 0 additions & 3 deletions lib/blocs/library/cubit/library_items_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:developer';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

import 'package:Bloomee/model/songModel.dart';
import 'package:Bloomee/screens/widgets/snackbar.dart';
import 'package:Bloomee/services/db/GlobalDB.dart';
import 'package:Bloomee/services/db/bloomee_db_service.dart';
import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart';

part 'library_items_state.dart';

class LibraryItemsCubit extends Cubit<LibraryItemsState> {
Expand Down
9 changes: 9 additions & 0 deletions lib/blocs/settings_cubit/cubit/settings_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ class SettingsCubit extends Cubit<SettingsState> {
.then((value) {
emit(state.copyWith(autoUpdateNotify: value ?? false));
});
BloomeeDBService.getSettingBool(GlobalStrConsts.autoSlideCharts)
.then((value) {
emit(state.copyWith(autoSlideCharts: value ?? true));
});
}

void updateAutoUpdateNotify(bool value) {
BloomeeDBService.putSettingBool(GlobalStrConsts.autoUpdateNotify, value);
emit(state.copyWith(autoUpdateNotify: value));
}

void updateAutoSlideCharts(bool value) {
BloomeeDBService.putSettingBool(GlobalStrConsts.autoSlideCharts, value);
emit(state.copyWith(autoSlideCharts: value));
}
}
6 changes: 5 additions & 1 deletion lib/blocs/settings_cubit/cubit/settings_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ part of 'settings_cubit.dart';

class SettingsState {
bool autoUpdateNotify;
bool autoSlideCharts;
SettingsState({
required this.autoUpdateNotify,
required this.autoSlideCharts,
});

SettingsState copyWith({
bool? autoUpdateNotify,
bool? autoSlideCharts,
}) {
return SettingsState(
autoUpdateNotify: autoUpdateNotify ?? this.autoUpdateNotify,
autoSlideCharts: autoSlideCharts ?? this.autoSlideCharts,
);
}
}

final class SettingsInitial extends SettingsState {
SettingsInitial() : super(autoUpdateNotify: false);
SettingsInitial() : super(autoUpdateNotify: false, autoSlideCharts: true);
}
1 change: 1 addition & 0 deletions lib/routes_and_consts/global_str_consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class GlobalStrConsts {
static const String ChartScreen = "ChartScreen";

static const String autoUpdateNotify = "auto_update_notify";
static const String autoSlideCharts = "auto_slide_charts";
}
20 changes: 18 additions & 2 deletions lib/screens/screen/home_views/setting_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:Bloomee/blocs/settings_cubit/cubit/settings_cubit.dart';
import 'package:Bloomee/services/db/GlobalDB.dart';
import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart';
import 'package:flutter/material.dart';

import 'package:Bloomee/screens/screen/home_views/setting_views/check_update_view.dart';
Expand Down Expand Up @@ -71,6 +69,24 @@ class _SettingsViewState extends State<SettingsView> {
onChanged: (value) {
context.read<SettingsCubit>().updateAutoUpdateNotify(value);
}),
SwitchListTile(
value: state.autoSlideCharts,
subtitle: Text(
"Slide charts automatically in home screen.",
style: TextStyle(
color: Default_Theme.primaryColor1.withOpacity(0.5),
fontSize: 14)
.merge(Default_Theme.secondoryTextStyleMedium),
),
title: Text(
"Auto slide charts",
style: const TextStyle(
color: Default_Theme.primaryColor1, fontSize: 20)
.merge(Default_Theme.secondoryTextStyleMedium),
),
onChanged: (value) {
context.read<SettingsCubit>().updateAutoSlideCharts(value);
}),
],
);
},
Expand Down
15 changes: 14 additions & 1 deletion lib/screens/widgets/carousal_widget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'dart:developer';
import 'package:Bloomee/blocs/explore/cubit/explore_cubits.dart';
import 'package:Bloomee/blocs/settings_cubit/cubit/settings_cubit.dart';
import 'package:Bloomee/screens/screen/chart/chart_widget.dart';
import 'package:Bloomee/screens/screen/chart/show_charts.dart';
import 'package:carousel_slider/carousel_slider.dart';
Expand All @@ -24,13 +26,24 @@ class _CaraouselWidgetState extends State<CaraouselWidget> {
bool _visibility = true;
final FetchChartCubit fetchChartCubit = FetchChartCubit();
List<ChartCubit> chartCubitList = List.empty(growable: true);
bool autoSlideCharts = true;

@override
void initState() {
for (var i in chartInfoList) {
chartCubitList.add(ChartCubit(i, fetchChartCubit));
}
super.initState();
context.read<SettingsCubit>().stream.listen((event) {
if (autoSlideCharts != event.autoSlideCharts) {
autoSlideCharts = event.autoSlideCharts;
if (autoSlideCharts) {
log("Auto Slide Charts Enabled");
} else {
log("Auto Slide Charts Disabled");
}
}
});
}

@override
Expand Down Expand Up @@ -74,7 +87,7 @@ class _CaraouselWidgetState extends State<CaraouselWidget> {
},
height: 320.0,
viewportFraction: 0.7,
// autoPlay: true,
autoPlay: autoSlideCharts,
autoPlayInterval: const Duration(milliseconds: 2500),
// aspectRatio: 15 / 16,
// enableInfiniteScroll: true,
Expand Down

0 comments on commit 4842411

Please sign in to comment.