커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
webview_flutter 설치 후 에뮬레이터 실행 시 에러 발생
[왕초보] 플러터(Flutter)로 시작하는 앱개발 종합반
4주차
북마크
김*수
댓글
7
추천
0
조회수
23
조회수
23
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


4주차 강의 webview_flutter 설치 후에 에뮬레이터를 "Run Without Debugging" 으로 실행하니까 아래와 같은 에러 발생가 발생합니다.


Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...

lib/main.dart:214:13: Error: The method 'WebView' isn't defined for the class 'WebViewPage'.

- 'WebViewPage' is from 'package:watcha_pedia/main.dart' ('lib/main.dart').

Try correcting the name to the name of an existing method, or defining a method named 'WebView'.

body: WebView(initialUrl: url),

^^^^^^^

Target kernel_snapshot_program failed: Exception

2


FAILURE: Build failed with an exception.


* What went wrong:

Execution failed for task ':app:compileFlutterBuildDebug'.

> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1


* Try:

> Run with --stacktrace option to get the stack trace.

> Run with --info or --debug option to get more log output.

> Run with --scan to get full insights.

> Get more help at https://help.gradle.org.


BUILD FAILED in 3s

Error: Gradle task assembleDebug failed with exit code 1


Exited (1).







import 'package:flutter/material.dart';

import 'package:provider/provider.dart';


import 'book.dart';

import 'book_service.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 StatefulWidget {

  HomePage({Key? key}) : super(key: key);


  @override

  State<HomePage> createState() => _HomePageState();

}


class _HomePageState extends State<HomePage> {

  var bottomNavIndex = 0;

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      body: [

        SearchPage(),

        LikedBookPage(),

      ].elementAt(bottomNavIndex),

      bottomNavigationBar: BottomNavigationBar(

        selectedItemColor: Colors.black,

        unselectedItemColor: Colors.grey,

        showUnselectedLabels: true,

        selectedFontSize: 12,

        unselectedFontSize: 12,

        iconSize: 28,

        type: BottomNavigationBarType.fixed,

        onTap: (value) {

          setState(() {

            bottomNavIndex = value;

          });

        },

        items: [

          BottomNavigationBarItem(

            icon: Icon(Icons.search),

            label: '검색',

          ),

          BottomNavigationBarItem(

            icon: Icon(Icons.star),

            label: '좋아요',

          ),

        ],

        currentIndex: bottomNavIndex,

      ),

    );

  }

}


class SearchPage extends StatelessWidget {

  SearchPage({super.key});


  @override

  Widget build(BuildContext context) {

    return Consumer<BookService>(builder: (context, bookService, child) {

      return Scaffold(

        appBar: AppBar(

          backgroundColor: Colors.white,

          toolbarHeight: 80,

          title: TextField(

            onSubmitted: (value) {

              bookService.search(value);

            },

            cursorColor: Colors.grey,

            decoration: InputDecoration(

              prefixIcon: Icon(Icons.search, color: Colors.grey),

              hintText: "작품, 감독, 배우, 컬렉션, 유저 등",

              border: OutlineInputBorder(

                borderSide: BorderSide(color: Colors.white),

                borderRadius: BorderRadius.all(Radius.circular(10)),

              ),

              focusedBorder: OutlineInputBorder(

                borderSide: BorderSide(color: Colors.grey),

                borderRadius: BorderRadius.all(Radius.circular(10)),

              ),

            ),

          ),

        ),

        body: Padding(

          padding: const EdgeInsets.symmetric(horizontal: 12),

          child: ListView.separated(

            itemCount: bookService.bookList.length,

            separatorBuilder: (context, index) {

              return Divider();

            },

            itemBuilder: (context, index) {

              if (bookService.bookList.isEmpty) return SizedBox();

              Book book = bookService.bookList.elementAt(index);

              return BookTile(book: book);

            },

          ),

        ),

      );

    });

  }

}


class BookTile extends StatelessWidget {

  const BookTile({

    super.key,

    required this.book,

  });


  final Book book;


  @override

  Widget build(BuildContext context) {

    BookService bookService = context.read<BookService>();


    return ListTile(

      onTap: () {

        Navigator.push(

          context,

          MaterialPageRoute(

            builder: (context) => WebViewPage(

              url: book.previewLink.replaceFirst("http", "https"),

            ),

          ),

        );

      },

      leading: Image.network(

        book.thumbnail,

        fit: BoxFit.fitHeight,

      ),

      title: Text(

        book.title,

        style: TextStyle(fontSize: 16),

      ),

      subtitle: Text(

        book.subtitle,

        style: TextStyle(color: Colors.grey),

      ),

      trailing: IconButton(

        onPressed: () {

          bookService.toggleLikeBook(book: book);

        },

        icon: bookService.likedBookList.map((book) => book.id).contains(book.id)

            ? Icon(

                Icons.star,

                color: Colors.amber,

              )

            : Icon(Icons.star_border),

      ),

    );

  }

}


class LikedBookPage extends StatelessWidget {

  const LikedBookPage({super.key});


  @override

  Widget build(BuildContext context) {

    return Consumer<BookService>(

      builder: (context, bookService, child) {

        return Scaffold(

          body: Padding(

            padding: const EdgeInsets.symmetric(horizontal: 12),

            child: ListView.separated(

              itemCount: bookService.likedBookList.length,

              separatorBuilder: (context, index) {

                return Divider();

              },

              itemBuilder: (context, index) {

                if (bookService.likedBookList.isEmpty) return SizedBox();

                Book book = bookService.likedBookList.elementAt(index);

                return BookTile(book: book);

              },

            ),

          ),

        );

      },

    );

  }

}


class WebViewPage extends StatelessWidget {

  WebViewPage({super.key, required this.url});


  String url;


  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(

        backgroundColor: Colors.grey,

        title: Text(url),

      ),

      body: WebView(initialUrl: url),

    );

  }

}





취소
 공유
취소
댓글 0
댓글 알림
나의얼굴