11import 'package:app/components/error_notifier.dart' ;
2+ import 'package:app/components/loading_dialog.dart' ;
23import 'package:app/components/login_page/rounded_button.dart' ;
34import 'package:app/controller/user_controller.dart' ;
5+ import 'package:app/hooks/use_api.dart' ;
6+ import 'package:app/models/book_models.dart' ;
47import 'package:flutter/material.dart' ;
58import 'package:http/http.dart' as http;
69
7-
810User ? myUser;
911
1012class OnboardScreen extends StatefulWidget {
@@ -16,7 +18,16 @@ class OnboardScreen extends StatefulWidget {
1618
1719class _OnboardScreenState extends State <OnboardScreen > {
1820 String myUri = 'https://www.projectlib.tk/' ;
19- void warp () {
21+ List <String > likedIsbnList = [];
22+ Future <List <Book >>? bookData;
23+
24+ void warp () async {
25+ myShowDialog (context, "로딩중입니다.." );
26+ if (likedIsbnList.isNotEmpty) {
27+ for (int i = 0 ; i < likedIsbnList.length; i++ ) {
28+ like (likedIsbnList[i]);
29+ }
30+ }
2031 Navigator .of (context).pushNamedAndRemoveUntil (
2132 '/home' ,
2233 (route) => false ,
@@ -25,20 +36,35 @@ class _OnboardScreenState extends State<OnboardScreen> {
2536 );
2637 }
2738
28- void like ( String isbn) async {
29-
39+ void handleClick () {}
40+ void like ( String isbn) async {
3041 await http.post (
42+ Uri .parse (myUri + 'like/?user_id=${myUser !.userId }&isbn=${isbn }/' ),
43+ headers: < String , String > {
44+ 'Content-Type' : 'application/json; charset=UTF-8' ,
45+ },
46+ );
47+ }
3148
32- Uri .parse (myUri + 'like/?user_id=${myUser !.userId }&isbn=${isbn }/' ),
49+ Future <List <Book >> fetchBooks () async {
50+ List <Book > tmp = [];
51+ for (int i = 0 ; i < firstIsbnList.length; i++ ) {
52+ tmp.add (
53+ Book .fromJson (await feedAladinApiGet (firstIsbnList[i].toString ())));
54+ }
55+ ;
56+ return tmp;
57+ }
3358
34- headers : < String , String > {
35- 'Content-Type' : 'application/json; charset=UTF-8' ,
36- },
37- );
59+ @override
60+ void initState () {
61+ super . initState ();
62+ bookData = fetchBooks ( );
3863 }
3964
4065 @override
4166 Widget build (BuildContext context) {
67+ Size size = MediaQuery .of (context).size;
4268 myUser = ModalRoute .of (context)! .settings.arguments as User ? ;
4369 if (myUser == null ) {
4470 return const Scaffold (
@@ -50,8 +76,118 @@ class _OnboardScreenState extends State<OnboardScreen> {
5076
5177 return Scaffold (
5278 body: Column (children: [
79+ FutureBuilder <List <Book >>(
80+ future: bookData,
81+ builder: (BuildContext context, bookList) {
82+ if (bookList.hasData) {
83+ return CustomScrollView (
84+ primary: false ,
85+ slivers: < Widget > [
86+ SliverPadding (
87+ padding: const EdgeInsets .all (0 ),
88+ sliver: SliverGrid .count (
89+ crossAxisSpacing: 10 ,
90+ mainAxisSpacing: 10 ,
91+ crossAxisCount: 1 ,
92+ childAspectRatio: 0.7 ,
93+ children: < Widget > [
94+ for (var _curBook in bookList.data! )
95+ Center (
96+ child: Card (
97+ margin: const EdgeInsets .symmetric (
98+ horizontal: 5.0 , vertical: 20.0 ),
99+ shape: RoundedRectangleBorder (
100+ borderRadius: BorderRadius .circular (10 ),
101+ ),
102+ elevation: 5 ,
103+ child: Padding (
104+ padding: const EdgeInsets .symmetric (
105+ vertical: 10 , horizontal: 15 ),
106+ child: SizedBox (
107+ width: double .infinity,
108+ child: Row (
109+ crossAxisAlignment:
110+ CrossAxisAlignment .center,
111+ mainAxisAlignment:
112+ MainAxisAlignment .spaceBetween,
113+ mainAxisSize: MainAxisSize .max,
114+ children: [
115+ ClipRRect (
116+ borderRadius:
117+ const BorderRadius .all (
118+ Radius .circular (10 )),
119+ child: Image (
120+ image: NetworkImage (
121+ _curBook.coverUrl),
122+ width: (size.width - 60 ) / 2 ,
123+ fit: BoxFit .fitWidth,
124+ ),
125+ ),
126+ SizedBox (
127+ width: 110 ,
128+ child: SingleChildScrollView (
129+ child: Column (
130+ crossAxisAlignment:
131+ CrossAxisAlignment .start,
132+ mainAxisAlignment:
133+ MainAxisAlignment .center,
134+ children: [
135+ Text (_curBook.title,
136+ style: const TextStyle (
137+ fontSize: 14.0 ,
138+ fontWeight:
139+ FontWeight .bold,
140+ color: Colors
141+ .black87)),
142+ const Divider (
143+ height: 30 ,
144+ endIndent: 10 ,
145+ indent: 10 ,
146+ color: Colors .black12,
147+ thickness: 3 ,
148+ ),
149+ Text ("지은이: " +
150+ _curBook.author),
151+ const Divider (
152+ height: 30 ,
153+ endIndent: 10 ,
154+ indent: 10 ,
155+ color: Colors .black12,
156+ thickness: 3 ,
157+ ),
158+ Text (_curBook.category),
159+ ],
160+ ),
161+ ))
162+ ]),
163+ ),
164+ )),
165+ )
166+ ],
167+ ),
168+ ),
169+ ],
170+ );
171+ } else if (bookList.hasError) {
172+ return ErrorNotifier (
173+ errorMessage: '리스트를 불러오는 데 문제가 생겼어요. 잠시 후 다시 시도해주세요.' ,
174+ );
175+ } else {
176+ return Column (children: const [
177+ SizedBox (
178+ child: CircularProgressIndicator (),
179+ width: 60 ,
180+ height: 60 ,
181+ ),
182+ Padding (
183+ padding: EdgeInsets .only (top: 16 ),
184+ child: Text ('로딩 중입니다...' ),
185+ )
186+ ]);
187+ }
188+ }),
53189 RoundedButton (
54- text: "로그인 " ,
190+ text: "완료 " ,
55191 press: warp,
56192 ),
57193 ]));
0 commit comments