Skip to content

Commit 7cf83c6

Browse files
Merge pull request #11 from Hypertext-Assassin-RSS/dev
Dev
2 parents dfbd580 + 7ecf939 commit 7cf83c6

File tree

12 files changed

+334
-128
lines changed

12 files changed

+334
-128
lines changed

.github/workflows/flutter-release-apk.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ jobs:
1616
with:
1717
flutter-version: '3.24.0'
1818

19+
- name: Set up .env file
20+
run: |
21+
mkdir -p assets/config
22+
echo "BASE_URL=${{ secrets.BASE_URL }}" > assets/config/.env
23+
1924
- name: Install dependencies
2025
run: flutter pub get
2126

.github/workflows/flutter-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ jobs:
1818
with:
1919
flutter-version: '3.24.0'
2020

21+
- name: Set up .env file
22+
run: |
23+
mkdir -p assets/config
24+
echo "BASE_URL=${{ secrets.BASE_URL }}" > assets/config/.env
25+
2126
- name: Install dependencies
2227
run: flutter pub get
2328

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ app.*.map.json
4141
/android/app/debug
4242
/android/app/profile
4343
/android/app/release
44+
45+
.env

assets/config/env

Whitespace-only changes.

assets/icons/logout.svg

Lines changed: 12 additions & 0 deletions
Loading

lib/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import 'src/screens/login.dart';
33
// ignore: unused_import
44
import 'package:mindful_reader/src/widgets/bottomnav.dart';
55
import './src/colors/color.dart';
6+
import 'package:flutter_dotenv/flutter_dotenv.dart';
67

7-
void main() {
8+
Future<void> main() async {
9+
await dotenv.load(fileName: "assets/config/.env");
810
runApp(const MyApp());
911
}
1012

lib/src/screens/banner.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ class BannerSection extends StatelessWidget {
2626
message = 'Warm Night!';
2727
}
2828

29-
String imageUrl = book['formats']['image/jpeg'] ?? 'assets/images/placeholder.png';
29+
String imageUrl = book['cover_url'] ?? 'assets/images/imgae_not.jpg';
3030
String title = book['title'] ?? 'Unknown Title';
31-
String author = book['authors'] != null && book['authors'].isNotEmpty
32-
? book['authors'][0]['name']
33-
: 'Unknown Author';
31+
String author = book['author'] ?? 'Unknown Author';
3432

3533
return Align(
3634
alignment: Alignment.center,

lib/src/screens/homepage.dart

Lines changed: 94 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import 'package:dio/dio.dart';
22
import 'package:flutter/material.dart';
33
import 'dart:math';
4+
import 'package:flutter_dotenv/flutter_dotenv.dart';
45

56
import 'banner.dart';
67
import 'category.dart';
78
import 'itemcards.dart';
89
import 'trends.dart';
910
import 'details.dart';
1011

12+
1113
class HomePage extends StatefulWidget {
1214
const HomePage({super.key});
1315

@@ -25,108 +27,111 @@ class _HomePageState extends State<HomePage> {
2527
fetchBooks();
2628
}
2729

28-
Future<void> fetchBooks() async {
29-
try {
30-
final response = await Dio().get('https://gutendex.com/books');
31-
if (response.statusCode == 200) {
32-
if (mounted) { // Check if the widget is still mounted
33-
setState(() {
34-
books = response.data['results'];
35-
isLoading = false;
36-
});
37-
}
38-
} else {
39-
throw Exception('Failed to load books');
40-
}
41-
} catch (e) {
42-
if (mounted) { // Check if the widget is still mounted
30+
Future<void> fetchBooks() async {
31+
await dotenv.load(fileName: "assets/config/.env");
32+
try {
33+
final response = await Dio().get('${dotenv.env['API_BASE_URL']}/books');
34+
if (response.statusCode == 200) {
35+
if (mounted) {
4336
setState(() {
37+
books = response.data;
4438
isLoading = false;
4539
});
4640
}
41+
} else {
42+
throw Exception('Failed to load books');
43+
}
44+
} catch (e) {
45+
if (mounted) {
46+
setState(() {
47+
isLoading = false;
48+
});
4749
}
50+
print('Error fetching books: $e');
4851
}
52+
}
4953

5054

51-
@override
52-
Widget build(BuildContext context) {
53-
final random = Random();
54-
final randomBook = books.isNotEmpty ? books[random.nextInt(books.length)] : null;
5555

56-
return Scaffold(
57-
body: SingleChildScrollView(
58-
scrollDirection: Axis.vertical,
59-
child: Column(
60-
children: [
61-
isLoading
62-
? const Center(child: CircularProgressIndicator())
63-
: BannerSection(book: randomBook),
64-
const SizedBox(height: 5),
65-
const CategoryCard(),
66-
const SizedBox(height: 5),
67-
SingleChildScrollView(
68-
scrollDirection: Axis.horizontal,
69-
child: Row(
70-
children: books.map((book) {
71-
return InkWell(
72-
onTap: () {
73-
Navigator.push(
74-
context,
75-
MaterialPageRoute(
76-
builder: (context) => DetailsScreen(
77-
imageUrl: book['formats']['image/jpeg'] ?? 'assets/images/imgae_not.jpg',
78-
title: book['title'] ?? 'Unknown Title',
79-
author: book['authors'].isNotEmpty ? book['authors'][0]['name'] : 'Unknown Author',
80-
description: book['description'] ?? 'No description available.',
81-
bookUrl: book['formats']['text/html']
82-
),
56+
@override
57+
Widget build(BuildContext context) {
58+
final random = Random();
59+
final randomBook = books.isNotEmpty ? books[random.nextInt(books.length)] : null;
60+
61+
return Scaffold(
62+
body: SingleChildScrollView(
63+
scrollDirection: Axis.vertical,
64+
child: Column(
65+
children: [
66+
isLoading
67+
? const Center(child: CircularProgressIndicator())
68+
: BannerSection(book: randomBook),
69+
const SizedBox(height: 5),
70+
const CategoryCard(),
71+
const SizedBox(height: 5),
72+
SingleChildScrollView(
73+
scrollDirection: Axis.horizontal,
74+
child: Row(
75+
children: books.map((book) {
76+
return InkWell(
77+
onTap: () {
78+
Navigator.push(
79+
context,
80+
MaterialPageRoute(
81+
builder: (context) => DetailsScreen(
82+
imageUrl: book['cover_url'] ?? 'assets/images/imgae_not.jpg',
83+
title: book['title'] ?? 'Unknown Title',
84+
author: book['author'] ?? 'Unknown Author',
85+
description: book['description'] ?? 'No description available.',
86+
bookUrl: book['pdf_url']
8387
),
84-
);
85-
},
86-
child: ItemCards(
87-
imagepic: book['formats']['image/jpeg'] ?? 'assets/images/imgae_not.jpg',
88-
text1: book['title'] ?? 'Unknown Title',
89-
text2: book['authors'].isNotEmpty ? book['authors'][0]['name'] : 'Unknown Author',
90-
),
91-
);
92-
}).toList(),
93-
),
88+
),
89+
);
90+
},
91+
child: ItemCards(
92+
imagepic: book['cover_url'] ?? 'assets/images/imgae_not.jpg',
93+
text1: book['title'] ?? 'Unknown Title',
94+
text2: book['author'] ?? 'Unknown Author',
95+
),
96+
);
97+
}).toList(),
9498
),
95-
const SizedBox(height: 10),
96-
const Trends(),
97-
const SizedBox(height: 15),
98-
SingleChildScrollView(
99-
scrollDirection: Axis.horizontal,
100-
child: Row(
101-
children: books.map((book) {
102-
return InkWell(
103-
onTap: () {
104-
Navigator.push(
105-
context,
106-
MaterialPageRoute(
107-
builder: (context) => DetailsScreen(
108-
imageUrl: book['formats']['image/jpeg'] ?? 'assets/images/imgae_not.jpg',
109-
title: book['title'] ?? 'Unknown Title',
110-
author: book['authors'].isNotEmpty ? book['authors'][0]['name'] : 'Unknown Author',
111-
description: book['description'] ?? 'No description available.',
112-
bookUrl: book['formats']['text/html']
113-
),
99+
),
100+
const SizedBox(height: 10),
101+
const Trends(),
102+
const SizedBox(height: 15),
103+
SingleChildScrollView(
104+
scrollDirection: Axis.horizontal,
105+
child: Row(
106+
children: books.map((book) {
107+
return InkWell(
108+
onTap: () {
109+
Navigator.push(
110+
context,
111+
MaterialPageRoute(
112+
builder: (context) => DetailsScreen(
113+
imageUrl: book['cover_url'] ?? 'assets/images/imgae_not.jpg',
114+
title: book['title'] ?? 'Unknown Title',
115+
author: book['author'] ?? 'Unknown Author',
116+
description: book['description'] ?? 'No description available.',
117+
bookUrl: book['pdf_url']
114118
),
115-
);
116-
},
117-
child: ItemCards(
118-
imagepic: book['formats']['image/jpeg'] ?? 'assets/images/imgae_not.jpg',
119-
text1: book['title'] ?? 'Unknown Title',
120-
text2: book['authors'].isNotEmpty ? book['authors'][0]['name'] : 'Unknown Author',
121-
),
122-
);
123-
}).toList(),
124-
),
119+
),
120+
);
121+
},
122+
child: ItemCards(
123+
imagepic: book['cover_url'] ?? 'assets/images/imgae_not.jpg',
124+
text1: book['title'] ?? 'Unknown Title',
125+
text2: book['author'] ?? 'Unknown Author',
126+
),
127+
);
128+
}).toList(),
125129
),
126-
const SizedBox(height: 20),
127-
],
128-
),
130+
),
131+
const SizedBox(height: 20),
132+
],
129133
),
130-
);
134+
),
135+
);
131136
}
132137
}

0 commit comments

Comments
 (0)