Skip to content

Commit

Permalink
chart imports from db
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Mar 22, 2024
1 parent bc338fb commit 75fab2e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
1 change: 0 additions & 1 deletion lib/blocs/explore/cubit/explore_cubits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:Bloomee/model/MediaPlaylistModel.dart';
import 'package:Bloomee/model/chart_model.dart';
import 'package:Bloomee/plugins/chart_defines.dart';
import 'package:Bloomee/repository/Youtube/yt_charts_home.dart';
import 'package:Bloomee/screens/screen/chart/show_charts.dart';
import 'package:Bloomee/services/db/bloomee_db_service.dart';

part 'explore_states.dart';
Expand Down
13 changes: 4 additions & 9 deletions lib/routes_and_consts/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:Bloomee/blocs/explore/cubit/explore_cubits.dart';
import 'package:Bloomee/model/chart_model.dart';
import 'package:Bloomee/plugins/chart_defines.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
import 'package:Bloomee/screens/screen/add_to_playlist_screen.dart';
Expand Down Expand Up @@ -82,16 +83,10 @@ class GlobalRoutes {
routes: [
GoRoute(
name: GlobalStrConsts.ChartScreen,
path: 'ChartScreen',
path: 'ChartScreen:chartName',
builder: (context, state) => ChartScreen(
chartCubit: () {
if (state.extra != null) {
return state.extra as ChartCubit;
} else {
return null;
}
}(),
)),
chartName:
state.pathParameters['chartName'] ?? "none")),
])
]),
StatefulShellBranch(routes: [
Expand Down
42 changes: 27 additions & 15 deletions lib/screens/screen/chart/chart_view.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:Bloomee/blocs/explore/cubit/explore_cubits.dart';
import 'package:Bloomee/model/chart_model.dart';
import 'package:Bloomee/services/db/bloomee_db_service.dart';
import 'package:flutter/material.dart';
import 'package:Bloomee/screens/widgets/chart_list_tile.dart';
import 'package:Bloomee/theme_data/default.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class ChartScreen extends StatefulWidget {
ChartCubit? chartCubit;
ChartScreen({Key? key, this.chartCubit}) : super(key: key);
// ChartCubit? chartCubit;
final String chartName;
ChartScreen({Key? key, required this.chartName}) : super(key: key);

@override
State<ChartScreen> createState() => _ChartScreenState();
}

class _ChartScreenState extends State<ChartScreen> {
Future<ChartModel?> chartModel = Future.value(null);
Future<ChartModel?> getChart() async {
return await BloomeeDBService.getChart(widget.chartName);
}

@override
void initState() {
setState(() {
chartModel = getChart();
});
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<ChartCubit, ChartState>(
bloc: widget.chartCubit,
body: FutureBuilder(
future: chartModel,
builder: (context, state) {
if (state is ChartInitial) {
if (state.connectionState == ConnectionState.waiting ||
state.data == null) {
return const Center(
child: SizedBox(
height: 50,
Expand All @@ -35,7 +46,7 @@ class _ChartScreenState extends State<ChartScreen> {
color: Default_Theme.accentColor2,
)),
);
} else if (state.chart.chartItems!.isEmpty) {
} else if (state.data!.chartItems!.isEmpty) {
return Center(
child: Text("Error: No Item in Chart",
style: Default_Theme.secondoryTextStyleMedium.merge(
Expand All @@ -44,22 +55,21 @@ class _ChartScreenState extends State<ChartScreen> {
color: Color.fromARGB(255, 255, 235, 251)))),
);
} else {
final ChartModel chart = state.chart;
return CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
customDiscoverBar(context, state), //AppBar
customDiscoverBar(context, state.data!), //AppBar
SliverList(
delegate: SliverChildListDelegate([
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: chart.chartItems!.length,
itemCount: state.data!.chartItems!.length,
itemBuilder: (context, index) {
return ChartListTile(
title: chart.chartItems![index].name!,
subtitle: chart.chartItems![index].subtitle!,
imgUrl: chart.chartItems![index].imageUrl!,
title: state.data!.chartItems![index].name!,
subtitle: state.data!.chartItems![index].subtitle!,
imgUrl: state.data!.chartItems![index].imageUrl!,
);
},
),
Expand All @@ -73,7 +83,7 @@ class _ChartScreenState extends State<ChartScreen> {
);
}

SliverAppBar customDiscoverBar(BuildContext context, ChartState state) {
SliverAppBar customDiscoverBar(BuildContext context, ChartModel state) {
return SliverAppBar(
floating: true,
surfaceTintColor: Default_Theme.themeColor,
Expand All @@ -83,7 +93,7 @@ class _ChartScreenState extends State<ChartScreen> {
centerTitle: false,
titlePadding:
const EdgeInsets.only(left: 8, bottom: 0, right: 0, top: 0),
title: Text(state.chart.chartName,
title: Text(state.chartName,
textScaleFactor: 1,
textAlign: TextAlign.start,
style: Default_Theme.secondoryTextStyleMedium.merge(const TextStyle(
Expand All @@ -93,7 +103,9 @@ class _ChartScreenState extends State<ChartScreen> {
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(state.coverImg), fit: BoxFit.cover),
image: NetworkImage(
state.chartItems!.first.imageUrl.toString()),
fit: BoxFit.cover),
),
),
Positioned.fill(
Expand Down
9 changes: 4 additions & 5 deletions lib/screens/widgets/carousal_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ class _CaraouselWidgetState extends State<CaraouselWidget> {
for (int i = 0; i < chartInfoList.length; i++)
InkWell(
onTap: () {
GoRouter.of(context).push(
"/${GlobalStrConsts.exploreScreen}/${GlobalStrConsts.ChartScreen}",
extra: chartCubitList[i]);
GoRouter.of(context).pushNamed(GlobalStrConsts.ChartScreen,
pathParameters: {"chartName": chartInfoList[i].title});
},
child: BlocProvider(
create: (context) => chartCubitList[i],
child: BlocProvider.value(
value: chartCubitList[i],
child: ChartWidget(
chartInfo: chartInfoList[i],
),
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ flutter:
assets:
- assets/icons/Bloomee_Logo.png
- assets/.env
- assets/icons/bloomee_new_logo_c.png

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down

0 comments on commit 75fab2e

Please sign in to comment.