cupertino_context_menu.0.dart 2.44 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flutter code sample for CupertinoContextMenu

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

10
void main() => runApp(const ContextMenuApp());
11

12
class ContextMenuApp extends StatelessWidget {
13
  const ContextMenuApp({super.key});
14 15 16

  @override
  Widget build(BuildContext context) {
17 18 19
    return const CupertinoApp(
      theme: CupertinoThemeData(brightness: Brightness.light),
      home: ContextMenuExample(),
20 21 22 23
    );
  }
}

24
class ContextMenuExample extends StatelessWidget {
25
  const ContextMenuExample({super.key});
26 27 28

  @override
  Widget build(BuildContext context) {
29 30 31 32 33
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        middle: Text('CupertinoContextMenu Sample'),
      ),
      child: Center(
34 35 36 37 38 39 40 41 42
        child: SizedBox(
          width: 100,
          height: 100,
          child: CupertinoContextMenu(
            actions: <Widget>[
              CupertinoContextMenuAction(
                onPressed: () {
                  Navigator.pop(context);
                },
43 44 45 46 47 48 49 50 51 52
                isDefaultAction: true,
                trailingIcon: CupertinoIcons.doc_on_clipboard_fill,
                child: const Text('Copy'),
              ),
              CupertinoContextMenuAction(
                onPressed: () {
                  Navigator.pop(context);
                },
                trailingIcon: CupertinoIcons.share,
                child: const Text('Share  '),
53 54 55 56 57
              ),
              CupertinoContextMenuAction(
                onPressed: () {
                  Navigator.pop(context);
                },
58 59 60 61 62 63 64 65 66 67
                trailingIcon: CupertinoIcons.heart,
                child: const Text('Favorite'),
              ),
              CupertinoContextMenuAction(
                onPressed: () {
                  Navigator.pop(context);
                },
                isDestructiveAction: true,
                trailingIcon: CupertinoIcons.delete,
                child: const Text('Delete'),
68 69
              ),
            ],
70
            child: Container(
71 72 73 74 75
              decoration: BoxDecoration(
                color: CupertinoColors.systemYellow,
                borderRadius: BorderRadius.circular(20.0),
              ),
              child: const FlutterLogo(size: 500.0),
76
            ),
77 78 79 80 81 82
          ),
        ),
      ),
    );
  }
}