1
votes

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

4 Answers

2
votes

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.

1
votes

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
}
0
votes

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
-1
votes

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