How to Quickly Develop a WebView App Using Flutter and Publish It on Play Store

0

Mobile websites are already in operation, but if you want to expand to native apps, using Flutter and WebView can develop apps quickly and efficiently. This article will explain step-by-step how to convert a mobile website to a Flutter app and register it on the Play Store. Additionally, we will also look at the differences between AdSense and AdMob and how to monetize ads in WebView apps.

1. Set Up Development Environment

Install Flutter

Refer to the installation guide for your operating system from the official Flutter site.

Install Android Studio

Install Android Studio and add the Flutter and Dart plugins.

2. Create a New Flutter Project

Create a new Flutter project in Android Studio.

  • Open Android Studio and select `File > New > New Flutter Project`.
  • Select `Flutter Application` and specify the project name and save location.

3. Add WebView Plugin

To add WebView functionality to your Flutter project, use the `webview_flutter` plugin.

First, open the `pubspec.yaml` file and add `webview_flutter` to the dependencies section:

dependencies:
      flutter:
        sdk: flutter
      webview_flutter: ^4.0.0  # Check for the latest version

Then save the changes and run the `flutter pub get` command to install the plugin.

4. Configure WebView

Open the `lib/main.dart` file and configure the WebView.

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: WebViewExample(),
    );
  }
}

class WebViewExample extends StatefulWidget {
  @override
  WebViewExampleState createState() => WebViewExampleState();
}

class WebViewExampleState extends State<WebViewExample> {
  @override
  void initState() {
    super.initState();
    // For Android, use Hybrid Composition.
    if (Platform.isAndroid) {
      WebView.platform = SurfaceAndroidWebView();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My Web App'),
      ),
      body: WebView(
        initialUrl: 'https://your-mobile-website.com', // Enter your website URL here.
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );
  }
}

5. Configure Android Settings

Open the `android/app/src/main/AndroidManifest.xml` file and add internet permission.

<uses-permission android:name="android.permission.INTERNET"/>

6. Build and Test

In Android Studio, select `Run > Run ‘main.dart’` to test the app on an emulator or actual device.

7. Register the App on the Play Store

Once the app works properly, the next step is to register it on the Play Store.

Set App Icon

Replace the icon files in the `android/app/src/main/res` directory with appropriate icons.

Sign the App

To register the app on the Play Store, you need to sign it. Refer to the official guide to generate the keystore file and set up signing.

Build the App

Use the `flutter build apk –release` command to generate the release APK file.

Register on the Play Store

Go to Google Play Console, create a new application, and upload the APK file. Enter the app information, review, and release the app.

8. Updating the App

Updating the app is also straightforward. Update the existing Flutter project, generate a new APK file, and upload it to the Play Store.

Apply Code Changes

Apply the necessary code changes to the app.

Update Version Number

Update the `versionCode` and `versionName` in the `android/app/build.gradle` file.

android {
    ...
    defaultConfig {
        ...
        versionCode 2 // Change to a number higher than the previous version
        versionName "1.1" // New version name
    }
    ...
}

Build Release APK

flutter build apk --release

Upload Updated APK to Play Store

Log in to Google Play Console, upload the new version, review, and release.

9. AdSense and AdMob in WebView Apps

If AdSense is applied to your existing mobile web, it may also appear in the WebView app, but you must check Google’s AdSense policy. AdSense may restrict usage in WebView apps. Alternatively, you can use AdMob to monetize ads.

Integrate AdMob

1. Create AdMob Account and Register App

Sign up at Google AdMob and register your app.

2. Create Ad Units

Create ad units such as banner ads and interstitial ads.

3. Add Plugin

Add the `google_mobile_ads` plugin to your Flutter project.

dependencies:
  google_mobile_ads: ^2.0.0
4. Initialize and Display Ads
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  MobileAds.instance.initialize();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  BannerAd? _bannerAd;

  @override
  void initState() {
    super.initState();
    _bannerAd = BannerAd(
      adUnitId: 'ca-app-pub-3940256099942544/6300978111', // Test ad unit ID
      size: AdSize.banner,
      request: AdRequest(),
      listener: BannerAdListener(),
    )..load();
  }

  @override
  void dispose() {
    _bannerAd?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AdMob Example'),
      ),
      body: Center(
        child: _bannerAd == null
            ? Text('Loading Ad...')
            : Container(
                alignment: Alignment.center,
                child: AdWidget(ad: _bannerAd!),
                width: _bannerAd!.size.width.toDouble(),
                height: _bannerAd!.size.height.toDouble(),
              ),
      ),
    );
  }
}

Differences Between AdSense and AdMob

AdSense targets website owners, while AdMob targets mobile app developers. Both are Google’s advertising platforms, but they differ in target platforms, ad formats, and integration methods.

  • AdSense: Serves ads on websites and blogs. Mainly text, image, and video ads.
  • AdMob: Serves ads in mobile apps. Banner, interstitial, native, and rewarded video ads.

You must follow Google’s policy to use AdSense in a WebView app, and AdMob might be more suitable.

Conclusion

Following this guide, you can learn how to quickly develop a WebView app using Flutter and register it on the Play Store. Understanding how to use AdSense and AdMob for ad monetization will help maximize your app’s revenue. This allows website operators to easily expand into mobile apps and reach more users.

Leave a Reply