0

I wanna implement YoutubePlayer in my Flutter project which runs in web and android platforms. I'm using youtube_player_flutter package for Android and embedded YouTube player view in web. How to separate both codes in single project?

Subair K
  • 1,760
  • 1
  • 11
  • 31

1 Answers1

0

You can use the dart:io packages Platform class to check the Platform that is running the code.

See https://api.flutter.dev/flutter/dart-io/Platform-class.html, there exists

Platform.isAndroid.

To check if you are deploying to web, there is a constant called kIsWeb in the flutter foundation. Use can use it like this:

import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io' show Platform;

if (kIsWeb) {
  // use this for web
} else if (Platform.isAndroid) {
  // use this for android
}
Matthias S
  • 3,358
  • 3
  • 21
  • 31