Home > database >  Make a Widget invisible based on current plattform
Make a Widget invisible based on current plattform

Time:02-21

I want to show the widget when I'm on android, and I want to make it invisible when I'm on iOS. I want to disable the Widget on iOS, cause the backup function doesn't work on IOS (need permission to file system). I've seen the posts about the visibility prefix, but I don't know how I can make this platform based.

Code:

ListTile(
            title: const Text('Backup & Wiederherstellen \n(Nur Android)'),
            leading: const Icon(Icons.restore),
            onTap: () {
              Storage storage = LocalStorage();
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => BackupAndRestorePage(
                    storage: storage,
                  ),
                ),
              );
            },
          ),

CodePudding user response:

You can use Visibilty for that. Additionally you have to import dart:io to check on what platform you currently are.

Visibility(
  visible: Platform.isAndroid,
  child: ListTile(
    title: const Text('Backup & Wiederherstellen \n(Nur Android)'),
    leading: const Icon(Icons.restore),
    onTap: () {
      Storage storage = LocalStorage();
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => BackupAndRestorePage(
            storage: storage,
          ),
        ),
      );
    },
  ),
);

CodePudding user response:

import dart:io and try this:


if(Platform.isAndroid)
  ListTile(
            title: const Text('Backup & Wiederherstellen \n(Nur Android)'),
            leading: const Icon(Icons.restore),
            onTap: () {
              Storage storage = LocalStorage();
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => BackupAndRestorePage(
                    storage: storage,
                  ),
                ),
              );
            },
          ),
  • Related