Skip to content

Flutter - Display a platform dependent Action Sheet

License

Notifications You must be signed in to change notification settings

gem85247/platform_action_sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Platform action sheet

Platform Pub

This package is a simple platform specific actionSheet for Cupertino and Android with the following options:

  • Text - (Required) String to display
  • onPressed - (Required) Function to be executed on the option item being pressed
  • hasArrow - Not visible on IOS, indicating more options will appear
  • isCancel
  • defaultAction

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  platform_action_sheet: ^0.0.3

In your library add the following import:

import 'package:platform_action_sheet/platform_action_sheet.dart';

For help getting started with Flutter, view the online documentation.

Example

import 'package:flutter/material.dart';
import 'package:platform_action_sheet/platform_action_sheet.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example App',
      home: new Home(),
    );
  }
}

class Home extends StatelessWidget {
  const Home({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Example App'),
      ),
      body: Center(
        child: FlatButton(
              color: Colors.blue,
              onPressed: () => PlatformActionSheet().displaySheet(
                  context: context,
                  title: Row(
                    children: <Widget>[
                      Text("Hello Mum"),
                      Icon(
                        Icons.beach_access,
                        color: Colors.blue,
                        size: 36.0,
                      ),
                    ],
                  ),
                  message: Text("I'm in London"),
                  actions: [
                    ActionSheetAction(
                      text: "Option 1",
                      onPressed: () => Navigator.pop(context),
                      hasArrow: true,
                    ),
                    ActionSheetAction(
                      text: "Option 2",
                      onPressed: () => Navigator.pop(context),
                    ),
                    ActionSheetAction(
                      text: "Cancel",
                      onPressed: () => Navigator.pop(context),
                      isCancel: true,
                      defaultAction: true,
                    )
                  ]),
              child: Text(
                'Display ActionSheet',
                textScaleFactor: 1.2,
                style: TextStyle(color: Colors.white),
              ),
        ),
      ),
    );
  }
}

About

Flutter - Display a platform dependent Action Sheet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages