본문 바로가기
카테고리 없음

창2 부트캠프 4주차

by 땡칠이 2022. 6. 25.
반응형

창업세션을 듣고나니 사업할때는 좋은 사람를 잘 만나서 해야될거같다. 초기에 공동창업시에도 수익분배나 근무기간 등 그러한 사항들을 잘 정해놓고 시작해야될 거 같다. 수업에서는 API dio SafeArea 등 유익한 시간이였다. 오늘 드는 생각이지만 플러터 잘 따라 가려고 노력하고 있지만 그래도 이 과정이 끝나도 계속 사용하고 배워보고 싶다. 

 

main.dart

 

import 'dart:js';

import 'package:book_store/book_service.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() {
  runApp(MultiProvider(
  providers: [ChangeNotifierProvider(create: (context) => BookService())],
  child: const MyApp()
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
     return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  TextEditingController _textEditingController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Consumer<BookService>(
      builder: (context, bookService, child) {
        return Scaffold(
          appBar: AppBar(
            centerTitle: false,
            title: Text(
              'Book Store',
              style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
            ),
            backgroundColor: Colors.white,
            bottom: PreferredSize(
              preferredSize: Size(0, 60), // bottom 영역 크기
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Column(
                  children: [
                    Container(
                      width: double.infinity,
                      child: Text(
                        'total ${bookService.bookList.length }',
                        textAlign: TextAlign.end,
                      ),
                    ),
                    TextField(
                      controller: _textEditingController ,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                            borderSide: BorderSide(color: Colors.blue)),
                        hintText: "원하시는 책을 검색해주세요",
                        suffixIcon: IconButton(
                          icon: Icon(Icons.search),
                          onPressed: () async{
                            print(_textEditingController.text);
                            if(_textEditingController.text.isNotEmpty);
                            Response response = await Dio().get(
                            'https://www.googleapis.com/books/v1/volumes',
                            queryParameters: {
                              'q': _textEditingController.text
                              },
                            );
                            print(response.data['kind']);
                            bookService.addBook(book);
                          },
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          body: ListView.builder(
            itemCount: bookService.bookList.length,
             itemBuilder: (context,index) {
                Book book = bookService.bookList[index];

              return ListTile(
                leading: Text('leading'),
                title: Text('title'),
                subtitle: Text('subtitle'),
                 );
             },
             ),
        );
      }
    );
  }
}

book.dart

class Book {
  String title;
  String subtitle;
  String thumbnail;
  String previewLink;

  Book({
    required this.title,
    required this.subtitle,
    required this.thumbnail,
    required this.previewLink,
    });
}

 

book_service.dart

import 'package:flutter/material.dart';

import 'book.dart';

class BookService extends ChangeNotifier {
  // 책 목록
  List<Book> bookList = [];

  void addBook(Book book){}

     notifyListeners();
    

  void clearBooks(){}
}

 

반응형

댓글