Flutter WebView

황인호·2022년 12월 11일
0

Main.dart

import 'package:flutter/material.dart';
import 'package:flutter_install_test/screen/home_screen.dart';

void main() {
  runApp(MaterialApp(
    home: HomeScreen(),
  ));
}

Home_screen.dart

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class HomeScreen extends StatelessWidget {
  WebViewController? controller;
  final HomeUrl = 'https://blog.codefactory.ai';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.orange,
          title: Text('Code Factory'),
          centerTitle: true,
          actions: [
            IconButton(
              onPressed: () {
                if (controller == null) {
                  return;
                }

                controller?.loadUrl(HomeUrl);
              },
              icon: Icon(
                Icons.home,
              ),
            )
          ],
        ),
        body: WebView(
          onWebViewCreated: (WebViewController controller) {
            this.controller = controller;
          },
          initialUrl: HomeUrl,
          javascriptMode: JavascriptMode.unrestricted,
        ));
  }
}

pubspec.yaml

build.gradle

profile
성장중인 백엔드 개발자!!

0개의 댓글