Search code examples
flutterflutter-webflutter-windows

Flutter Windows: how can we add Header and footer in same code while we have code for mobile?


I have flutter 2.10 SDK but there is no documentation on native web Replacements. please anyone throw light on this issue.


Solution

  • What you need to do is to execute code based on the host platform.

    First import the relevant headers

    import 'dart:io' show Platform;
    

    Using Platform APIs now you can detect the host platform and execute your codes for target platforms:

    void myCode() {
      if (Platform.isWindows) {
        // do something specific for Windows here
      } else {
        // do something for other platforms
      }
    }