CodeBlanks Logo Icon CodeBlanks

Web vs mobile

Learn behavioral differences between web and mobile.

Web vs mobile difference

kIsWeb is a constant bool telling whether the app is running on the web. You use an adapter to handle platform differences; for example, mouse events on web and touch events on mobile are handled differently.

import 'package:flutter/foundation.dart';

if (kIsWeb) {
  // web-specific code
} else {
  // mobile code
}

adapter pattern

To use the same interface on different platforms, you write an adapter. The adapter picks the right implementation per platform; for example, a MouseEvent on web and a TapEvent on mobile.

Practice kIsWeb check

In main, assign kIsWeb to isWeb and print it.

Starter code

main.dart
import 'package:flutter/foundation.dart';

void main() {
  // web durumunu foundation'dan alıp isWeb değişkenine ata
  // yazdır
}

Sample solution

main.dart
import 'package:flutter/foundation.dart';

void main() {
  final isWeb = kIsWeb;
  print(isWeb);
}

Expected output

false

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does kIsWeb indicate?

  • Screen resolution
  • App size
  • Whether the app runs on web Correct answer
  • Device model

Explanation: kIsWeb is a constant bool that tells whether the app runs on the web platform; size, model and resolution are not kIsWeb's job.

2 kIsWeb check

Question
if (____) {
  // web kodu
}
Answer
if (kIsWeb) {
  // web kodu
}

Explanation: kIsWeb is the constant bool from flutter/foundation; isWeb, web and onWeb are not valid constants in dart:ffi or flutter.

3 Web vs mobile matches

Term Meaning
platform Target environment
kIsWeb Web check
adapter Platform bridge
mobil Touch event

All lessons in Expert