Let us look at a Flutter CupertinoActionSheet example.

Example 1: Flutter CupertinoActionSheet Examples

Learn how to create a CupertinoActionSheet using the following simple examples.

  1. Open your favorite Flutter IDE.
  2. Go to File-->New-->Project to create a new project.

Here are the examples:

  • CupertinoActionSheetExample.dart

Example 1: CupertinoActionSheet Example

Write your code as follows:

*CupertinoActionSheetExample.dart

Create a file Dart named CupertinoActionSheetExample.dart

Add two imports: Cupertino and material:

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

Extend the StatelessWidget class:

class CupertinoActionSheetExample extends StatelessWidget {

Define a title variable and a constructor to accept that title:

  final String title;
  const CupertinoActionSheetExample(this.title);

Here is the full code

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

class CupertinoActionSheetExample extends StatelessWidget {
  final String title;
  const CupertinoActionSheetExample(this.title);

  @override
  Widget build(BuildContext context) {
    return CupertinoApp(
      home: CupertinoPageScaffold(
        navigationBar: CupertinoNavigationBar(
          previousPageTitle: "Back",
          middle: Text(title),
        ),
        child: const CupertinoActionSheet(
          actions: <Widget>[
            Center(child: Text("First Action")),
            Center(child: Text("Second Action")),
          ],
          cancelButton: Center(child: Text("Cancel")),
        ),
      ),
    );
  }
}

Reference.

Download code here.
Follow code author here.

Read Individually.


Categorized in: