skip to Main Content

I am trying to place a FAQ in my flutter app and tried to run through the docs but is unsure how to use the "Platform.isAndroid" and "Platform.isiOS" to display different flutter texts for different platform.

Source: https://docs.flutter.dev/resources/platform-adaptations

ListTile(
    title: Text('1. What is a question?'),
    subtitle: Text('This is the first answer to Android. || This is the second answer to iOS.'),
),

Any guidance?

2

Answers


  1. Chosen as BEST ANSWER

    After a few mingling around, I found this solution.

     ListTile(
                title: Text('1. What is a question?'),
                subtitle: Text(Platform.isAndroid
                    ? 'This is the answer for Android.'
                    : (Platform.isIOS
                        ? 'This is the answer for iOS.'
                        : 'This is the default answer for other platforms.')),
              ),
    

  2. Why not just declare a text variable, and use Platform, with an if/else block (or switch/case block) to assign it’s value?

    if (Platform.isIOS) { 
        myText = "ABC";
    } else if (Platform.isAndroid) { 
        myText = "DEF";
    } else {
        ...
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search