platform_object

Last updated:

0 purchases

platform_object Image
platform_object Images
Add to Cart

Description:

platform object

This package will help you write clean flutter apps without branching code for each platform
Features #

Supports iOS,Android, Web, MacOSX, Linux, Windows, Funchsia

Getting started #
For installation just include platform_object in your pubspec.yml
dependencies:
platform_object:
Usage #
Usage is super simple, just initialize your platform object with the necessery values
final platformString = PlatformObject(ios: "ios", android: "android").value;
print("Hello $platformString"); // Will print "Hello iOS" or "Hello Android" depending on the platform
copied to clipboard
You can quickly scale this and see how much you can clean up your codes. For example let's say you want to display platform specific buttons on your app. You can implement it like below:
class MyiOSButton extends StatelessWidget {
const MyiOSButton({super.key});

@override
Widget build(BuildContext context) {
return const CupertinoButton(
child: const Text('My iOS Button'),
onPressed: null,
);
}
}

class MyAndroidButton extends StatelessWidget {
const MyAndroidButton({super.key});

@override
Widget build(BuildContext context) {
return const TextButton(
onPressed: null,
child: Text('My Android button'),
);
}
}

// Main app
class MyPage extends StatelessWidget {
const MyPage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
// Just include the platform object with the widgets per platform
child: PlatformObject(
ios: const MyiOSButton(),
android: const MyAndroidButton())
.value),
);
}
}
copied to clipboard
Additional information #
The implementation of this class is simple and it is using final to minimize the overhead on the runtime
If you have any questions, ideas or feedbacks do not hesitate to contact. Happy coding!

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.