Ad

Make A Widget Invisible Based On Current Plattform

- 1 answer

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,
                  ),
                ),
              );
            },
          ),
Ad

Answer

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,
          ),
        ),
      );
    },
  ),
);
Ad
source: stackoverflow.com
Ad