Skip to content

Instantly share code, notes, and snippets.

@lesnitsky
Last active January 20, 2020 11:09
Show Gist options
  • Save lesnitsky/8fb80e6519b93b72e8c397c3a380e014 to your computer and use it in GitHub Desktop.
Save lesnitsky/8fb80e6519b93b72e8c397c3a380e014 to your computer and use it in GitHub Desktop.
How to detect if flutter app is running in web
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
const BE_HOST = 'https://api.dev';
class AppConfig {
static String BE_ENDPOINT;
}
void main() {
if (kIsWeb) {
AppConfig.BE_ENDPOINT = '$BE_HOST/web/';
} else if (Platform.isAndroid) {
AppConfig.BE_ENDPOINT = '$BE_HOST/android/';
}
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Text(AppConfig.BE_ENDPOINT),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment