mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-08 20:50:04 +00:00
New Example - Platform Adaptive Example (#121)
* Adding Platform Adaptive Example * Adding screenshots
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:using_platform_adaptive/platform_adaptive.dart';
|
||||
|
||||
class AdaptiveButton extends PlatformAdaptiveWidget {
|
||||
const AdaptiveButton(
|
||||
{super.forcePlatform,
|
||||
this.color,
|
||||
required this.child,
|
||||
this.onPressed,
|
||||
super.key});
|
||||
|
||||
final void Function()? onPressed;
|
||||
final Widget child;
|
||||
final Color? color;
|
||||
|
||||
@override
|
||||
Widget buildAndroid(BuildContext context) {
|
||||
return MaterialButton(
|
||||
onPressed: onPressed,
|
||||
color: color,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildIOS(BuildContext context) {
|
||||
return CupertinoButton(
|
||||
onPressed: onPressed,
|
||||
color: color,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:using_platform_adaptive/platform_adaptive.dart';
|
||||
|
||||
class AdaptiveDialog extends PlatformAdaptiveWidget {
|
||||
const AdaptiveDialog(
|
||||
{super.key,
|
||||
super.forcePlatform,
|
||||
required this.title,
|
||||
required this.actions,
|
||||
this.content});
|
||||
|
||||
final String title;
|
||||
final Widget? content;
|
||||
final List<AdaptiveDialogAction> actions;
|
||||
|
||||
@override
|
||||
Widget buildAndroid(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: content,
|
||||
actions: actions,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildIOS(BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(title),
|
||||
content: content,
|
||||
actions: actions,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AdaptiveDialogAction extends PlatformAdaptiveWidget {
|
||||
const AdaptiveDialogAction(
|
||||
{super.forcePlatform, this.onPressed, required this.text, super.key});
|
||||
|
||||
final void Function()? onPressed;
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget buildAndroid(BuildContext context) {
|
||||
return TextButton(onPressed: onPressed, child: Text(text));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildIOS(BuildContext context) {
|
||||
return CupertinoDialogAction(onPressed: onPressed, child: Text(text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:using_platform_adaptive/platform_adaptive.dart';
|
||||
|
||||
class AdaptiveIndicator extends PlatformAdaptiveWidget {
|
||||
const AdaptiveIndicator({super.forcePlatform, super.key});
|
||||
|
||||
@override
|
||||
Widget buildAndroid(BuildContext context) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildIOS(BuildContext context) {
|
||||
return const CupertinoActivityIndicator();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user