Giter VIP home page Giter VIP logo

marianocordoba / fab-circular-menu Goto Github PK

View Code? Open in Web Editor NEW
200.0 4.0 69.0 94 KB

A Flutter package to create a nice circular menu using a Floating Action Button.

Home Page: https://pub.dev/packages/fab_circular_menu

License: MIT License

Dart 88.49% Kotlin 1.87% Swift 2.25% Objective-C 0.21% Ruby 4.22% Shell 2.96%
flutter flutter-package floatingactionbutton floating-action-button floatingactionmenu menu

fab-circular-menu's Introduction

FAB Circular Menu

Pub Pull Requests are welcome Codemagic build status Null safety

A Flutter package to create a nice circular menu using a Floating Action Button.

Inspired by Mayur Kshirsagar's great FAB Microinteraction design.

Showcase

Installation

Just add fab_circular_menu to your pubspec.yml file

dependencies:
  fab_circular_menu: ^1.0.0

Example

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Placeholder(),
        floatingActionButton: FabCircularMenu(
          children: <Widget>[
            IconButton(icon: Icon(Icons.home), onPressed: () {
              print('Home');
            }),
            IconButton(icon: Icon(Icons.favorite), onPressed: () {
              print('Favorite');
            })
          ]
        )
      )
    );
  }
}

You can check for a more complete example in the example directory.

Customize

You can customize the widget appareance using the following properties:

Property Description Default
alignment Sets the widget alignment Alignment.bottomRight
ringColor Sets the ring color accentColor
ringDiameter Sets the ring diameter screenWidth * 1.25 (portrait)
screenHeight * 1.25 (landscape)
ringWidth Sets the ring width ringDiameter * 0.3
fabSize Sets the FAB size 64.0
fabElevation Sets the elevation for the FAB 8.0
fabColor Sets the FAB color primaryColor
fabOpenColor Sets the FAB color while the menu is open. This property takes precedence over fabColor -
fabCloseColor Sets the FAB color while the menu is closed. This property takes precedence over fabColor -
fabChild Sets the child inside the FAB. This property takes precedence over fabOpenicon and fabCloseIcon -
fabOpenIcon Sets the FAB icon while the menu is open Icon(Icons.menu)
fabCloseIcon Sets the FAB icon while the menu is closed Icon(Icons.close)
fabMargin Sets the widget margin EdgeInsets.all(16.0)
animationDuration Changes the animation duration Duration(milliseconds: 800)
animationCurve Allows you to modify the animation curve Curves.easeInOutCirc
onDisplayChange This callback is called every time the menu is opened or closed, passing the current state as a parameter. -

Handling the menu programmatically

It is possible to handle the menu programatically by using a key. Just create a key and set it in the key property of the FabCircularMenu, then use the key to get the current state and open, close or check the status of the menu.

class MyApp extends StatelessWidget {
  final GlobalKey<FabCircularMenuState> fabKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: RaisedButton(
          onPressed: () {
            if (fabKey.currentState.isOpen) {
              fabKey.currentState.close();
            } else {
              fabKey.currentState.open();
            }
          },
          child: Text('Toggle menu')
        ),
        floatingActionButton: FabCircularMenu(
          key: fabKey,
          children: <Widget>[
            // ...
          ]
        )
      )
    );
  }
}

Contributing

I will be very happy if you contribute to this project, please submit a PR ๐Ÿ˜

fab-circular-menu's People

Contributors

marianocordoba avatar mbjoern avatar mrcsabatoth avatar pepeexpress avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fab-circular-menu's Issues

Need ringWidth, please Advise?

Hi, I am trying out my project on Web too. Thats where I need the ringWidth. I see you get this from ringDiameter.. and that from screenWidth.

Is there any recommended way that I may get that present ringWidth? Besides doing the entire thing from scratch with Screen class??
Also, if there isnt, how may I know when the widget has finished its constructor, because thats the time I might try to trap the fabKey.currentState.widget.ringDiameter value into a double variable.

thanks,
Great package by the way!

Null Safety

We need null safety support for this package. Please :)

opTap is not working on children

I just wrap children in GestureDetector so I can do something onTap. but it's not working.

options: <Widget>[
              GestureDetector(
                behavior: prefix0.HitTestBehavior.opaque,
                onTap: () => print('1'),
                child: IconButton(
                  icon: Icon(Icons.widgets),
                  onPressed: () {},
                  iconSize: 48.0,
                  color: Colors.red,
                ),
              ),
              GestureDetector(
                onTap: () => print('2'),
                child: IconButton(
                  icon: Icon(Icons.widgets),
                  onPressed: () {},
                  iconSize: 48.0,
                  color: Colors.white,
                ),
              ),
              GestureDetector(
                onTap: () => print('3'),
                child: IconButton(
                  icon: Icon(Icons.widgets),
                  onPressed: () {},
                  iconSize: 48.0,
                  color: Colors.white,
                ),
              )
            ],

FAB icon color

There is no option to set/change the FAB icon color. It defaults to black and no way to change it.

image

Menu not auto close after clicked on menu item

After clicked on one menu item, I want a solution to close menu by code but I can't found anyway to do it at the moment. This feature is quite comment, I think it should be an item in wishlist features :)
Thanks for your time.

Change ringDiameter/ ringWidth: Lower button at right seems to be lost the click event

Hey! Congrats for this project! It's unique at this time!

  1. Using version: 1.0.0

2 This is the code structure:

`floatingActionButton: FabCircularMenu(
        alignment: Alignment.bottomRight,
        ringWidth: 130,
        children: <Widget>[
          IconButton(
              iconSize: 40,
              icon: Icon(
                Icons.home,
              ),
              onPressed: () {
                print('Home');
              }),
          IconButton(
              iconSize: 40,
              icon: Icon(
                Icons.favorite,
                size: 40,
              ),
              onPressed: () {
                controller.go2List();
                print('GoToLists');
              }),
          IconButton(
              iconSize: 40,
              icon: Icon(
                Icons.favorite,
                size: 40,
              ),
              onPressed: () {
                print('Favorite');
              }),
          IconButton(
              iconSize: 40,
              icon: Icon(
                Icons.favorite,
                size: 40,
              ),
              onPressed: () {
                print('Favorite');
              }),
          IconButton(
              iconSize: 40,
              icon: Icon(
                Icons.favorite,
                size: 40,
              ),
              onPressed: () {
                print('Favorite');
              }),
        ],
        ringColor: Color.fromARGB(70, 255, 255, 255),
      ),`
  1. The issue
    The first icon in the list ( Icons.home, ) seems to be unclickable... But sometimes is possible to do the click, somewhere around the icon... (kind of offset region)

where is FabCircularMenuController and how can i import that

could yuu help me how can i do that?

Hey! First of all, thanks for waiting. I've just added a controller property that takes a FabCircularMenuController which allows you to control the menu programatically.

final controller = FabCircularMenuController();

FabCircularMenu(
  child: ...,
  controller: controller,
  options: <Widget>[
    IconButton(icon: Icon(Icons.widgets), onPressed: () {
      controller.isOpen = false;
    }, iconSize: 48.0, color: Colors.white),
    ...
  ],
 )

I will improve documentation and examples soon.

Originally posted by @marianocordoba in #4 (comment)

One option should not be allowed

If there is only one option passed to this widget, it will crash because of this line trying to divide by zero:

  final double angle = 90.0 / (widgets.length * 2 - 2) * (index * 2);

I discovered it by pressing save after adding only one option, and hot reload resulted in an error.

some probs

  1. why do you force the child parameter? seems it is not really necessary.
  2. I suggest to assert required params, e.g. FabCircularMenu(...) : assert(child != null), assert(options != null && options.length > 0);
  3. If you want to provide this code as a library you need to move it to the lib/src folder and provide a dart file with export statements. See other libs. Currently I am unable to use your code as a lib. I rather copied the source code into my own repository instead.
  4. Please add a dispose method:
    @override
    void dispose() {
      controller?.dispose();
      super.dispose();
    }
  1. I still struggle when using 4 icons. In closed state the middle icons 1 and 2 are shown in the right-bottom corner beneath the fab.

grafik

grafik

You may find the problem, I don't currently.

  1. Seems it is not allowed to init the controller twice. Move that initialization to the initState() method instead:
  @override
  void initState() {
    super.initState();
    controller = AnimationController(duration: widget.animationDuration, vsync: this);
  }

Exception when use controller to close

Hi. when use it inside tab view, after change of tab, I have this exception:

Basically in this case we need use animation after dispose, any idea?

AnimationController.reverse() called after AnimationController.dispose()
AnimationController methods should not be used after calling dispose.
'package:flutter/src/animation/animation_controller.dart':
Failed assertion: line 488 pos 7: '_ticker != null'

First button not shown with bottomNavigationBar using a TabSelector

Hi,

First, thanks for the nice plugin from my point of view it's a good addition when it comes to usability and quick navigation.

I'm facing an issue that the first button in my list is hidden, it is drawn under the "bottomNavigationBar" which is in my case a TabSelecgtor widget. The image below shows the situation:

menu

This is the code of the menu, please note the page is nested into another view using Scaffold to render the above mentioned bottom bar.

Scaffold(
        body: ListView(
          children: listItems,
        ),
        floatingActionButton: state is ProjectHomeEditDetailsState
            ? null
            : Builder(
                builder: (context) => FabCircularMenu(
                  key: fabKey,
                  ringWidth: 50,
                  alignment: Alignment(1, 1),
                  ringDiameter: min(MediaQuery.of(context).size.width,
                          MediaQuery.of(context).size.height) *
                      0.9,
                  children: <Widget>[
                   //Not shown
                    IconButton(
                        icon: Icon(Icons.delete_forever),
                        onPressed: () {},
                       ),
                    // All below are shown
                    IconButton(
                        icon: Icon(Icons.edit),
                         onPressed: () {},
                     ),
                    IconButton(
                      icon: Icon(Icons.search),
                      onPressed: () {},
                    ),
                    IconButton(
                      icon: Icon(Icons.sync),
                      onPressed: () {},
                    ),
                  ],
                ),
              ),
      );

Having More scrollable items

Thanks to sharing very awesome library.
I have a question
In this library how can we have more scrollable items? By default there are fixed items with counts. For example can we have 50 scrollable items?

aligment have some problem

when i set builder: (context) => FabCircularMenu( key: fabKey, // Cannot be Alignment.centeralignment: **Alignment**(0.8,0.8), ringColor: Colors.white, ringDiameter: 500.0, ringWidth: 120.0, fabSize: 64.0, fabElevation: 8.0, the problem is FabCircularMenu's children widget is disorder.

if the plugin can support floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked argment , it will be perfect project .

More of a Question than an issue - how to add text below the icon?

I tried to create a Column widget with the Icon and the Text widget, but then the button would be placed in a random place far away from where it was supposed to. I even tried the column as a child of the RawMaterialButton, but same result.

Is it possible to add text below the icon with this package? I would love know. Great package thanks for the content!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.