Last active
January 20, 2020 11:09
-
-
Save lesnitsky/8fb80e6519b93b72e8c397c3a380e014 to your computer and use it in GitHub Desktop.
How to detect if flutter app is running in web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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