Reputation: 65
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
Upvotes: 2
Views: 3490
Reputation: 2990
According to the documentation You need to run these commands in your terminal:
flutter channel stable
flutter upgrade
flutter config --enable-web
flutter create .
Upvotes: 1
Reputation: 7100
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
}
Upvotes: 1
Reputation: 5086
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.
Upvotes: 2
Reputation: 1183
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
Upvotes: -1