Skip to content

Commit

Permalink
Merge pull request #8 from Riviu-Buku/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
SamuelTanielM authored Dec 20, 2023
2 parents bcabf24 + a1946c0 commit eff3ccb
Show file tree
Hide file tree
Showing 27 changed files with 1,513 additions and 604 deletions.
157 changes: 99 additions & 58 deletions album/lib/albumpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:review/reviewpage.dart';
import 'package:album/editalbum.dart';
import 'package:album/albumspage.dart';

class AlbumDetailsPage extends StatefulWidget {
final Album album;
Expand All @@ -18,7 +19,7 @@ class AlbumDetailsPage extends StatefulWidget {

class _AlbumDetailsPageState extends State<AlbumDetailsPage> {
Future<List<Book>> fetchBooksForAlbum(Album album) async {
var url = Uri.parse('http://127.0.0.1:8000/json/');
var url = Uri.parse('https://riviu-buku-d07-tk.pbp.cs.ui.ac.id/json/');
var response = await http.get(
url,
headers: {"Content-Type": "application/json"},
Expand Down Expand Up @@ -46,7 +47,23 @@ class _AlbumDetailsPageState extends State<AlbumDetailsPage> {
User user = widget.user;
return Scaffold(
appBar: AppBar(
title: Text(widget.album.fields.name),
title: Text(
widget.album.fields.name,
style: TextStyle(fontFamily: 'Roboto', fontWeight: FontWeight.bold),
),
backgroundColor: Color.fromRGBO(147, 129, 255, 1.000),
foregroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.home),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => AlbumsPage(user: widget.user),
),
);
},
),
actions: [
if (canEditAlbum())
IconButton(
Expand All @@ -62,65 +79,89 @@ class _AlbumDetailsPageState extends State<AlbumDetailsPage> {
),
],
),
body: FutureBuilder(
future: fetchBooksForAlbum(widget.album),
builder: (context, AsyncSnapshot<List<Book>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(widget.album.fields.name, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
SizedBox(height: 16),
// TODO: Implement the rest of your UI here
Expanded(
child: GridView.builder(
itemCount: snapshot.data!.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0,
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {Navigator.push(
context,
MaterialPageRoute(
builder: (context){
return ReviewPage(
book: snapshot.data![index], user: user,
);
}
),
);
},
child: Card(
child: Column(
children: <Widget>[
Expanded(
child: Image.network(
snapshot.data![index].fields?.coverImg ?? "",
fit: BoxFit.cover, // this will resize and crop the image to fit the box
),
body: Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color.fromARGB(255, 191, 156, 239),
Color.fromARGB(255, 216, 191, 247),
Color.fromARGB(255, 255, 223, 182),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: FutureBuilder(
future: fetchBooksForAlbum(widget.album),
builder: (context, AsyncSnapshot<List<Book>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.album.fields.name,
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: Colors.white),
),
SizedBox(height: 16),
Expanded(
child: GridView.builder(
itemCount: snapshot.data!.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ReviewPage(
book: snapshot.data![index], user: user,
);
}
),
Text((snapshot.data![index].fields?.title) ?? 'Default Title'),
],
);
},
child: Card(
elevation: 5.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: <Widget>[
Expanded(
child: Image.network(
snapshot.data![index].fields?.coverImg ?? "",
fit: BoxFit.cover,
),
),
Text(
(snapshot.data![index].fields?.title) ?? 'Default Title',
style: TextStyle(color: Color.fromARGB(255, 107, 66, 117)),
),
],
),
),
),
);
},
);
},
),
),
),
],
),
);
}
},
],
),
);
}
},
),
),
);
}
Expand Down
Loading

0 comments on commit eff3ccb

Please sign in to comment.