-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from FltSv/105-book-screen
#105 書籍一覧ページと書籍詳細ページの内部実装、ダミーデータの作成
- Loading branch information
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:mobile/models/creator.dart'; | ||
import 'package:mobile/providers/data_provider.dart'; | ||
|
||
/// 書籍 | ||
class Book { | ||
Book({ | ||
required this.id, | ||
required this.title, | ||
required this.image, | ||
required this.urls, | ||
}); | ||
|
||
final String id; | ||
|
||
/// 書籍のタイトル | ||
final String title; | ||
|
||
/// 書籍のサムネイル画像のファイル名+トークン | ||
final String image; | ||
String get imageUrl => DataProvider().getImageUrl(creator.id, image); | ||
|
||
/// 書籍購入のリンク 複数ある場合も可 | ||
final List<String> urls; | ||
|
||
late final Creator creator; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:gap/gap.dart'; | ||
import 'package:intersperse/intersperse.dart'; | ||
import 'package:mobile/models/book.dart'; | ||
import 'package:mobile/widgets/link_text.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
class BookDetailScreen extends StatefulWidget { | ||
const BookDetailScreen({ | ||
super.key, | ||
required this.book, | ||
}); | ||
|
||
final Book book; | ||
|
||
@override | ||
State<BookDetailScreen> createState() => _BookDetailScreenState(); | ||
} | ||
|
||
class _BookDetailScreenState extends State<BookDetailScreen> { | ||
@override | ||
Widget build(BuildContext context) { | ||
final book = widget.book; | ||
|
||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(book.title), | ||
), | ||
body: ListView( | ||
padding: const EdgeInsets.all(16), | ||
children: [ | ||
Image.network(book.image), | ||
const Gap(8), | ||
...book.urls.map((urltext) => LinkText( | ||
text: urltext, | ||
onTap: () async { | ||
final url = Uri.parse(urltext); | ||
await launchUrl(url, mode: LaunchMode.externalApplication); | ||
})) | ||
].intersperse(const Gap(8)).toList(), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:gap/gap.dart'; | ||
import 'package:mobile/models/book.dart'; | ||
import 'package:mobile/providers/data_provider.dart'; | ||
import 'package:mobile/providers/navigate_provider.dart'; | ||
import 'package:mobile/screens/book_detail_screen.dart'; | ||
import 'package:mobile/widgets/empty_state.dart'; | ||
|
||
class BookListScreen extends StatefulWidget { | ||
const BookListScreen({super.key}); | ||
|
||
@override | ||
State<BookListScreen> createState() => _BookListScreenState(); | ||
} | ||
|
||
class _BookListScreenState extends State<BookListScreen> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('書籍一覧'), | ||
), | ||
body: GridView.count( | ||
padding: const EdgeInsets.all(16), | ||
crossAxisCount: 2, | ||
mainAxisSpacing: 8, | ||
crossAxisSpacing: 8, | ||
physics: const NeverScrollableScrollPhysics(), // GridViewのスクロールを無効化 | ||
shrinkWrap: true, // GridViewの高さをコンテンツに合わせる | ||
children: _getResults(), | ||
), | ||
); | ||
} | ||
|
||
List<Widget> _getResults() { | ||
final results = DataProvider() | ||
.books | ||
.map((book) => BookItem(book: book)) | ||
.map<Widget>((item) => GestureDetector( | ||
onTap: () => NavigateProvider.push( | ||
context, BookDetailScreen(book: item.book)), | ||
child: item, | ||
)) | ||
.toList(); | ||
|
||
return results.isEmpty | ||
? [ | ||
const Gap(16), | ||
const EmptyState(message: '表示可能な書籍が見つかりませんでした。'), | ||
] | ||
: results; | ||
} | ||
} | ||
|
||
class BookItem extends StatelessWidget { | ||
const BookItem({ | ||
super.key, | ||
required this.book, | ||
}); | ||
|
||
final Book book; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Image.network(book.image); | ||
} | ||
} |