From 5382ded50c116dc61d70084d30a755ec4153c6b8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 8 Apr 2020 11:59:39 +1000 Subject: [PATCH] Add FAB context menu for the StockItem view - Uses flutter_speed_dial plugin --- lib/widget/stock_detail.dart | 47 +++++++++++++++++++++++++++++++++--- pubspec.lock | 7 ++++++ pubspec.yaml | 1 + 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index feb93548..ab4a7225 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -11,6 +11,7 @@ import 'package:InvenTree/api.dart'; import 'package:InvenTree/widget/drawer.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:flutter_speed_dial/flutter_speed_dial.dart'; class StockDetailWidget extends StatefulWidget { @@ -152,6 +153,43 @@ class _StockItemDisplayState extends State { return tiles; } + /* + * Return a list of context-sensitive action buttons. + * Not all buttons will be avaialable for a given StockItem, + * depending on the properties of that StockItem + */ + List actionButtons() { + var buttons = List(); + + buttons.add(SpeedDialChild( + child: Icon(Icons.add_circle), + label: "Add Stock", + onTap: null, + ) + ); + + buttons.add(SpeedDialChild( + child: Icon(Icons.remove_circle), + label: "Remove Stock", + onTap: null, + ), + ); + + buttons.add(SpeedDialChild( + child: Icon(Icons.check_circle), + label: "Count Stock", + onTap: null, + )); + + buttons.add(SpeedDialChild( + child: Icon(Icons.location_on), + label: "Transfer Stock", + onTap: null, + )); + + return buttons; + } + @override Widget build(BuildContext context) { return Scaffold( @@ -159,10 +197,11 @@ class _StockItemDisplayState extends State { title: Text("Stock Item"), ), drawer: new InvenTreeDrawer(context), - floatingActionButton: FloatingActionButton( - child: FaIcon(FontAwesomeIcons.ellipsisH), - // TODO: Add pop-up icons - // REF: https://stackoverflow.com/questions/46480221/flutter-floating-action-button-with-speed-dial#46480722 + floatingActionButton: SpeedDial( + visible: true, + animatedIcon: AnimatedIcons.menu_close, + heroTag: 'stock-item-fab', + children: actionButtons(), ), body: Center( child: ListView( diff --git a/pubspec.lock b/pubspec.lock index da7e2374..fa4c5ec7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -83,6 +83,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.7.4" + flutter_speed_dial: + dependency: "direct main" + description: + name: flutter_speed_dial + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.5" flutter_svg: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 175e6ae7..b34b622b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: qr_utils: ^0.1.4 # Barcode / QR-code support package_info: ^0.4.0+16 # App information introspection font_awesome_flutter: ^8.8.1 # FontAwesome icon set + flutter_speed_dial: ^1.2.5 # FAB menu elements dev_dependencies: flutter_test: