Skip to content

Commit

Permalink
ext_chart selection settings implt. feature
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Aug 5, 2024
1 parent cc81053 commit 54533ff
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 40 deletions.
17 changes: 17 additions & 0 deletions lib/blocs/settings_cubit/cubit/settings_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:developer';
import 'package:Bloomee/model/source_engines.dart';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
Expand Down Expand Up @@ -102,6 +103,22 @@ class SettingsCubit extends Cubit<SettingsState> {
log(switches.toString(), name: 'SettingsCubit');
});
}

Map chartMap = Map.from(state.chartMap);
BloomeeDBService.getSettingStr(GlobalStrConsts.chartShowMap).then((value) {
if (value != null) {
chartMap = jsonDecode(value);
}
emit(state.copyWith(chartMap: Map.from(chartMap)));
});
}

void setChartShow(String title, bool value) {
Map chartMap = Map.from(state.chartMap);
chartMap[title] = value;
BloomeeDBService.putSettingStr(
GlobalStrConsts.chartShowMap, jsonEncode(chartMap));
emit(state.copyWith(chartMap: Map.from(chartMap)));
}

void autoUpdate() {
Expand Down
6 changes: 6 additions & 0 deletions lib/blocs/settings_cubit/cubit/settings_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SettingsState extends Equatable {
bool autoGetCountry;
String countryCode;
List<bool> sourceEngineSwitches;
Map chartMap;
SettingsState({
required this.autoUpdateNotify,
required this.autoSlideCharts,
Expand All @@ -29,6 +30,7 @@ class SettingsState extends Equatable {
required this.autoGetCountry,
required this.countryCode,
required this.sourceEngineSwitches,
required this.chartMap,
});

SettingsState copyWith({
Expand All @@ -45,6 +47,7 @@ class SettingsState extends Equatable {
bool? autoGetCountry,
String? countryCode,
List<bool>? sourceEngineSwitches,
Map? chartMap,
}) {
return SettingsState(
autoUpdateNotify: autoUpdateNotify ?? this.autoUpdateNotify,
Expand All @@ -61,6 +64,7 @@ class SettingsState extends Equatable {
countryCode: countryCode ?? this.countryCode,
sourceEngineSwitches:
List.from(sourceEngineSwitches ?? this.sourceEngineSwitches),
chartMap: Map.from(chartMap ?? this.chartMap),
);
}

Expand All @@ -79,6 +83,7 @@ class SettingsState extends Equatable {
autoGetCountry,
countryCode,
sourceEngineSwitches,
chartMap,
];
}

Expand All @@ -98,5 +103,6 @@ class SettingsInitial extends SettingsState {
autoGetCountry: true,
countryCode: "IN",
sourceEngineSwitches: SourceEngine.values.map((e) => true).toList(),
chartMap: {},
);
}
19 changes: 19 additions & 0 deletions lib/plugins/ext_charts/chart_defines.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:math';

import 'package:Bloomee/model/chart_model.dart';
Expand All @@ -15,13 +16,31 @@ class ChartInfo {
final String title;
String imgUrl;
final ChartURL url;
bool show;

ChartInfo({
required this.chartFunction,
required this.title,
required this.imgUrl,
required this.url,
this.show = true,
});

ChartInfo copyWith({
ChartFunction? chartFunction,
String? title,
String? imgUrl,
ChartURL? url,
bool? show,
}) {
return ChartInfo(
chartFunction: chartFunction ?? this.chartFunction,
title: title ?? this.title,
imgUrl: imgUrl ?? this.imgUrl,
url: url ?? this.url,
show: show ?? this.show,
);
}
}

class RandomIMGs {
Expand Down
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 @@ -25,4 +25,5 @@ class GlobalStrConsts {
static const String historyClearTime = "autoHistoryCleanupTime";
static const String autoGetCountry = "autoGetCountry";
static const String countryCode = "countryCode";
static const String chartShowMap = "chartShowMap";
}
33 changes: 32 additions & 1 deletion lib/screens/screen/home_views/setting_views/appui_setting.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:Bloomee/blocs/settings_cubit/cubit/settings_cubit.dart';
import 'package:Bloomee/model/source_engines.dart';
import 'package:Bloomee/screens/screen/chart/show_charts.dart';
import 'package:flutter/material.dart';
import 'package:Bloomee/theme_data/default.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -91,7 +92,37 @@ class _AppUISettingsState extends State<AppUISettings> {
SourceEngine.values.indexOf(e), b);
});
}).toList(),
)
),
ExpansionTile(
title: Text(
"Allowed Chart Sources",
style: const TextStyle(
color: Default_Theme.primaryColor1, fontSize: 16)
.merge(Default_Theme.secondoryTextStyleMedium),
),
subtitle: Text(
"Manage the chart sources you want to see in the home screen.",
style: TextStyle(
color: Default_Theme.primaryColor1.withOpacity(0.5),
fontSize: 12)
.merge(Default_Theme.secondoryTextStyleMedium),
),
collapsedIconColor: Default_Theme.primaryColor1,
children: chartInfoList.map((e) {
return SwitchListTile(
value: state.chartMap[e.title] ?? true,
title: Text(
e.title,
style: const TextStyle(
color: Default_Theme.primaryColor1,
fontSize: 17)
.merge(Default_Theme.secondoryTextStyleMedium),
),
onChanged: (b) {
context.read<SettingsCubit>().setChartShow(e.title, b);
});
}).toList(),
),
],
);
},
Expand Down
86 changes: 47 additions & 39 deletions lib/screens/widgets/carousal_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CaraouselWidget extends StatefulWidget {
CaraouselWidget({
super.key,
}) {
chartInfoList.shuffle();
// chartInfoList.shuffle();
}

@override
Expand Down Expand Up @@ -86,45 +86,53 @@ class _CaraouselWidgetState extends State<CaraouselWidget> {
),
),
),
CarouselSlider(
options: CarouselOptions(
onPageChanged: (index, _) {
setState(() {
_visibility = index == 0;
});
},
height: ResponsiveBreakpoints.of(context).isMobile ||
ResponsiveBreakpoints.of(context).isTablet
? MediaQuery.of(context).size.height * 0.36
: 250,
viewportFraction: ResponsiveBreakpoints.of(context).isMobile
? 0.65
: ResponsiveBreakpoints.of(context).isTablet
? 0.30
: 0.25,
autoPlay: autoSlideCharts,
autoPlayInterval: const Duration(milliseconds: 2500),
// aspectRatio: 15 / 16,
// enableInfiniteScroll: true,
enlargeFactor: 0.2,
initialPage: 0,
pauseAutoPlayOnTouch: true,
enlargeCenterPage: true,
),
items: [
for (int i = 0; i < chartInfoList.length; i++)
BlocProvider.value(
value: chartCubitList[i],
child: GestureDetector(
onTap: () => GoRouter.of(context).pushNamed(
GlobalStrConsts.ChartScreen,
pathParameters: {"chartName": chartInfoList[i].title}),
child: ChartWidget(
chartInfo: chartInfoList[i],
),
),
BlocBuilder<SettingsCubit, SettingsState>(
builder: (context, state) {
return CarouselSlider(
options: CarouselOptions(
onPageChanged: (index, _) {
setState(() {
_visibility = index == 0;
});
},
height: ResponsiveBreakpoints.of(context).isMobile ||
ResponsiveBreakpoints.of(context).isTablet
? MediaQuery.of(context).size.height * 0.36
: 250,
viewportFraction: ResponsiveBreakpoints.of(context).isMobile
? 0.65
: ResponsiveBreakpoints.of(context).isTablet
? 0.30
: 0.25,
autoPlay: autoSlideCharts,
autoPlayInterval: const Duration(milliseconds: 2500),
// aspectRatio: 15 / 16,
// enableInfiniteScroll: true,
enlargeFactor: 0.2,
initialPage: 0,
pauseAutoPlayOnTouch: true,
enlargeCenterPage: true,
),
],
items: [
for (int i = 0; i < chartInfoList.length; i++)
if (state.chartMap[chartInfoList[i].title] == null ||
state.chartMap[chartInfoList[i].title] == true)
BlocProvider.value(
value: chartCubitList[i],
child: GestureDetector(
onTap: () => GoRouter.of(context).pushNamed(
GlobalStrConsts.ChartScreen,
pathParameters: {
"chartName": chartInfoList[i].title
}),
child: ChartWidget(
chartInfo: chartInfoList[i],
),
),
),
],
);
},
),
],
);
Expand Down

0 comments on commit 54533ff

Please sign in to comment.