Showing posts with label Flutter. Show all posts
Showing posts with label Flutter. Show all posts

23 June, 2022

flutter/Android WebView not loading an HTTPS or http URL


flutter/Android WebView not loading an HTTPS or http  URL

flutter/Android WebView not loading an HTTPS or http  URL


You can use the WebView plugin to display a webpage within your Flutter application. A Flutter plugin that provides a WebView widget.

Step 1:

Install web view using the following command 

  •  flutter pub add webview_flutter

Step 2:

user android:usesCleartextTraffic="true" to run  HTTP sites. not require for  HTTPS websites


Step 3:

Final Code: You can use the following code to run the website under android

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

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

class WebViewApp extends StatefulWidget {
  const WebViewApp({Key? key}) : super(key: key);

  @override
  State<WebViewApp> createState() => _WebViewAppState();
}

class _WebViewAppState extends State<WebViewApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter WebView'),
      ),
      body: const WebView(
        initialUrl: 'https://www.stackoverflowtips.com/',
      ),
    );
  }
}

Compile your code and have it run in an emulator:

sample output from code labs. developers. google. com



Bonus Point

You  may face the following issue "Android Webview gives net::ERR_CACHE_MISS message"

You can fix this issue by 

  • go to AndroidManifest.xml
  • add the following configuration
    • <uses-permission android:name="android.permission.INTERNET" />
  • Ensure that you don't have webView.getSettings().setBlockNetworkLoads (false);

09 March, 2021

Flutter: How to fix “unexpected element found in ” error?

 All of a sudden, I am started getting this build error in my Android project:


Error: unexpected element <queries> found in <manifest>

Understanding  the Issue:

To understanding why this happens see the above @CommonsWare's answer


This is because <queries> tag was introduced with new package visibility options for Android 11 and upwards (SDK 30+). Because of that, you need to update your build.gradle with a version that includes this changes. Below is a list of supported gradle options.

The best solution to deal with these errors is to Upgrade your Android Gradle plugin and Update Gradle

You’ll have to update your Gradle version to one of the compatible versions that have the latest query tags (which were introduced with Android 11).

How to Fix it?

To Update the Android Gradle plugin

Specify the plugin version in the YourAppDirectory/android/build.gradle file. The plugin version applies to all modules built-in that Android Studio project. The following example sets the plugin to version 4.0.1:


buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
    }
}

Gradle downloads it the next time you build your project 

To Update Gradle

Specify the Gradle version by editing the Gradle distribution reference in the YourAppDirectory/android/gradle/wrapper/gradle-wrapper.properties file.

Don't forget to update your ditributionUrl in your gradle-wrapper.properties as well. For example, for gradle 4.0.1, you should have:

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip


Flutter: mobX store code generate not working

 

 mobX store code generate not working

I had a same issue and I was able to solve with following steps.

I had this problem today and put these versions and it worked, in case anyone needs

You need to follow just couple of steps. Here is my pubspec.yaml package version for the mobx

Step 1:

  • Flutter (Channel stable, 1.22.6)
  • mobx: ^1.2.1+2
  • build_runner: 1.10.1
  • mobx_codegen: ^1.1.0+1

Step 2: run following commands

  • flutter clean
  • flutter pub get
  • flutter packages upgrade
  • flutter pub run build_runner watch --delete-conflicting-outputs
I trust it will help you :)

04 March, 2021

How to downgrade flutter?

 How to downgrade flutter?




You can downgrade using following setups:

Git Hub Source Code


Flutter is versioned using git. Changing the Flutter version is as simple as changing git branch.

Using Flutter Channel:


flutter channel <branch> (example: flutter channel stable)
This command is used to change between branches – usually stable/dev/beta/master. We can also put a specific commit id from git.

Flutter Downgrade Command:


flutter downgrade <version> (example: flutter downgrade v1.22.6)
This command will use a specific version number. You can have the list of the available version numbers using flutter downgrade or here

Then run  flutter doctor and Flutter will take care of downloading/compiling everything required to run this version.

22 December, 2020

Flutter Commands List

 

Command to check flutter version:

D:\>flutter --version

Output:

Flutter 1.20.4 • channel unknown • unknown source

Framework • revision fba99f6cf9 (3 months ago) • 2020-09-14 15:32:52 -0700

Engine • revision d1bc06f032

Tools • Dart 2.9.2


 To generate an app bundle, run:

        flutter build appbundle --target-platform android-arm,android-arm64,android-x64

        Learn more on: 

    To split the APKs per ABI, run:

        flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi

        Learn more on:  

Resolve Conflicts: 

flutter packages pub run build_runner watch --delete-conflicting-outputs

Here is some useful command List:  run flutter help <command>  to get command related information

Command Name

Example

Comments

analyze

flutter analyze -d <DEVICE_ID>

Analyzes the project’s Dart source code.

Use instead of dartanalyzer.

assemble

flutter assemble -o <DIRECTORY>

Assemble and build flutter resources.

attach

flutter attach -d <DEVICE_ID>

Attach to a running application.

bash-completion

flutter bash-completion

Output command line shell completion setup scripts.

build

flutter build <DIRECTORY>

Flutter build commands.

channel

flutter channel <CHANNEL_NAME>

List or switch flutter channels.

config

flutter config --build-dir=<DIRECTORY>

Configure Flutter settings. To remove a setting, configure it to an empty string.

create

flutter create <DIRECTORY>

Creates a new project.

devices

flutter devices -d <DEVICE_ID>

List all connected devices.

doctor

flutter doctor

Show information about the installed tooling.

downgrade

flutter downgrade

Downgrade Flutter to the last active version for the current channel.

drive

flutter drive

Runs Flutter Driver tests for the current project.

emulators

flutter emulators

List, launch and create emulators.

format

flutter format <DART_FILE>

Format one or more dart files.

gen-l10n

flutter gen-l10n <DIRECTORY>

Generate localizations for the Flutter project.

install

flutter install -d <DEVICE_ID>

Install a Flutter app on an attached device.

logs

flutter logs

Show log output for running Flutter apps.

format

flutter format <DIRECTORY|DART_FILE>

Formats Flutter source code.

Use instead of dartfmt.

precache

flutter precache <ARGUMENTS>

Populates the Flutter tool’s cache of binary artifacts.

pub

flutter pub <PUB_COMMAND>

Works with packages.

Use instead of pub.

run

flutter run <DART_FILE>

Runs a Flutter program.

symbolize

flutter symbolize --input=<STACK_TRACK_FILE>

Symbolize a stack trace from the AOT compiled flutter application.

test

flutter test [<DIRECTORY|DART_FILE>]

Runs tests in this package.

Use instead of pub run test.

upgrade

flutter upgrade

Upgrade your copy of Flutter.