popup_menu_2 0.0.7 copy "popup_menu_2: ^0.0.7" to clipboard
popup_menu_2: ^0.0.7 copied to clipboard

outdated

a pupup menu, contains clickable buttons each, and a global click function referring the item, this is for porpose not break the user attention,.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:popup_menu_2/contextual_menu.dart';
import 'package:popup_menu_2/popup_menu_item.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.blue, primaryColor: Colors.white),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  double _counter = 0;
  GlobalKey key = GlobalKey();

  void _incrementCounter() async {
    await Future.delayed(const Duration(milliseconds: 500));
    debugPrint('awaited successfully');

    setState(() {
      _counter++;
    });
  }

  void _decrementCounter() async {
    await Future.delayed(const Duration(milliseconds: 500));
    debugPrint('awaited successfully');
    setState(() {
      _counter--;
    });
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          bottom: AppBar(
            actions: [
              PhysicalModel(
                color: Colors.grey,
                shape: BoxShape.circle,
                elevation: 10,
                child: add(context),
              ),
            ],
          ),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:',
              ),
              Text(
                _counter.toStringAsFixed(3),
                style: Theme.of(context).textTheme.headline4,
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget add(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(12.0),
      child: ContextualMenu(
        targetWidgetKey: key,
        ctx: context,
        maxColumns: 1,
        backgroundColor: Colors.red,
        highlightColor: Colors.white,
        onDismiss: () {
          setState(() {
            _counter = _counter * 1.2;
          });
        },
        items: [
          CustomPopupMenuItem(
            press: _incrementCounter,
            title: 'increment',
            textAlign: TextAlign.justify,
            textStyle: const TextStyle(color: Colors.white),
            image: const Icon(Icons.add, color: Colors.white),
          ),
          CustomPopupMenuItem(
            press: _decrementCounter,
            title: 'decrement',
            textAlign: TextAlign.justify,
            textStyle: const TextStyle(color: Colors.white),
            image: const Icon(Icons.remove, color: Colors.white),
          ),
        ],
        child: Icon(
          Icons.add,
          key: key,
          color: Colors.white,
        ),
      ),
    );
  }
}
15
likes
0
pub points
81%
popularity

Publisher

unverified uploader

a pupup menu, contains clickable buttons each, and a global click function referring the item, this is for porpose not break the user attention,.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cupertino_icons, flutter

More

Packages that depend on popup_menu_2