2

How do I build the flutter app that can be built for web and the same application be used on our existing android/ios apps.

We already do have existing apps, we are looking to move towards flutter. Can we build a piece of our app in flutter, plug it into existing apps and use the same app in web too?

Abhi

4 Answers 4

2

To enable Flutter Web

flutter config --enable-web

then go into an existing Flutter project and run

flutter create .

and your project will be configured for web.

To disable Web:

flutter config --no-enable-web

More info here.

Sign up to request clarification or add additional context in comments.

Comments

1

You may use conditional import:

import 'some_package_stub.dart'
    if (dart.library.io) 'some_package_io.dart'
    if (dart.library.html) 'some_package_web.dart';

some_package_stub.dart file is required to avoid error while developing and compiling. It must contains some stub functionality which depends on running platform.

For example if you use function getPlatformDependedData from package some_package which returns different data under Web or Android, than you should declare the prototype of those function ins some_package_stub.dart:

String getPlatformDependedData() {
  throw UnimplementedError('This error will not raised!');
}

Then in the code you can use isWeb constant to check if code is web related:

if (isWeb) {
  // some web related statements
}

Comments

1

According to the documentation You need to run these commands in your terminal:

  1. flutter channel stable
  2. flutter upgrade
  3. flutter config --enable-web
  4. Restart your project
  5. flutter create .
  6. Done

Comments

-1

With regards to the question: can I build a flutter app that can be run in browsers, flutter for the web has been launched recently. You can find more info here:flutter web

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.