mirror of
https://github.com/inventree/inventree-app.git
synced 2025-07-02 03:40:47 +00:00
Format Code and Add Format Checks to CI (#643)
* Remove unused lib/generated/i18n.dart * Use `fvm dart format .` * Add contributing guidelines * Enforce dart format * Add `dart format off` directive to generated files
This commit is contained in:
@ -10,12 +10,10 @@ import "package:inventree/widget/back.dart";
|
||||
import "package:inventree/widget/drawer.dart";
|
||||
import "package:inventree/widget/search.dart";
|
||||
|
||||
|
||||
/*
|
||||
* Simple mixin class which defines simple methods for defining widget properties
|
||||
*/
|
||||
mixin BaseWidgetProperties {
|
||||
|
||||
/*
|
||||
* Return a list of appBar actions
|
||||
* By default, no appBar actions are available
|
||||
@ -23,7 +21,9 @@ mixin BaseWidgetProperties {
|
||||
List<Widget> appBarActions(BuildContext context) => [];
|
||||
|
||||
// Return a title for the appBar (placeholder)
|
||||
String getAppBarTitle() { return "--- app bar ---"; }
|
||||
String getAppBarTitle() {
|
||||
return "--- app bar ---";
|
||||
}
|
||||
|
||||
// Function to construct a drawer (override if needed)
|
||||
Widget getDrawer(BuildContext context) {
|
||||
@ -38,7 +38,6 @@ mixin BaseWidgetProperties {
|
||||
|
||||
// Function to construct a body
|
||||
Widget getBody(BuildContext context) {
|
||||
|
||||
// Default implementation is to return a ListView
|
||||
// Override getTiles to replace the internal context
|
||||
return ListView(
|
||||
@ -51,7 +50,6 @@ mixin BaseWidgetProperties {
|
||||
* Construct the top AppBar for this view
|
||||
*/
|
||||
AppBar? buildAppBar(BuildContext context, GlobalKey<ScaffoldState> key) {
|
||||
|
||||
List<Widget> tabs = getTabIcons(context);
|
||||
|
||||
return AppBar(
|
||||
@ -70,8 +68,10 @@ mixin BaseWidgetProperties {
|
||||
* - Button to access global search
|
||||
* - Button to access barcode scan
|
||||
*/
|
||||
BottomAppBar? buildBottomAppBar(BuildContext context, GlobalKey<ScaffoldState> key) {
|
||||
|
||||
BottomAppBar? buildBottomAppBar(
|
||||
BuildContext context,
|
||||
GlobalKey<ScaffoldState> key,
|
||||
) {
|
||||
const double iconSize = 40;
|
||||
|
||||
List<Widget> icons = [
|
||||
@ -90,10 +90,8 @@ mixin BaseWidgetProperties {
|
||||
onPressed: () {
|
||||
if (InvenTreeAPI().checkConnection()) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SearchWidget(true)
|
||||
)
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => SearchWidget(true)),
|
||||
);
|
||||
}
|
||||
},
|
||||
@ -106,27 +104,27 @@ mixin BaseWidgetProperties {
|
||||
scanBarcode(context);
|
||||
}
|
||||
},
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
return BottomAppBar(
|
||||
shape: AutomaticNotchedShape(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(40)),
|
||||
),
|
||||
shape: AutomaticNotchedShape(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
notchMargin: 10,
|
||||
child: IconTheme(
|
||||
data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: icons,
|
||||
)
|
||||
)
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(40)),
|
||||
),
|
||||
),
|
||||
notchMargin: 10,
|
||||
child: IconTheme(
|
||||
data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: icons,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -146,7 +144,6 @@ mixin BaseWidgetProperties {
|
||||
* Build out action buttons for a given widget
|
||||
*/
|
||||
Widget? buildSpeedDial(BuildContext context) {
|
||||
|
||||
final actions = actionButtons(context);
|
||||
final barcodeActions = barcodeButtons(context);
|
||||
|
||||
@ -165,44 +162,38 @@ mixin BaseWidgetProperties {
|
||||
spacing: 14,
|
||||
childPadding: const EdgeInsets.all(5),
|
||||
spaceBetweenChildren: 15,
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (actions.isNotEmpty) {
|
||||
children.add(
|
||||
SpeedDial(
|
||||
icon: Icons.more_horiz,
|
||||
activeIcon: Icons.close,
|
||||
children: actions,
|
||||
spacing: 14,
|
||||
childPadding: const EdgeInsets.all(5),
|
||||
spaceBetweenChildren: 15,
|
||||
)
|
||||
SpeedDial(
|
||||
icon: Icons.more_horiz,
|
||||
activeIcon: Icons.close,
|
||||
children: actions,
|
||||
spacing: 14,
|
||||
childPadding: const EdgeInsets.all(5),
|
||||
spaceBetweenChildren: 15,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Wrap(
|
||||
direction: Axis.horizontal,
|
||||
children: children,
|
||||
spacing: 15,
|
||||
);
|
||||
return Wrap(direction: Axis.horizontal, children: children, spacing: 15);
|
||||
}
|
||||
|
||||
// Return list of "tabs" for this widget
|
||||
List<Widget> getTabIcons(BuildContext context) => [];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Abstract base class which provides generic "refresh" functionality.
|
||||
*
|
||||
* - Drag down and release to 'refresh' the widget
|
||||
* - Define some method which runs to 'refresh' the widget state
|
||||
*/
|
||||
abstract class RefreshableState<T extends StatefulWidget> extends State<T> with BaseWidgetProperties {
|
||||
|
||||
abstract class RefreshableState<T extends StatefulWidget> extends State<T>
|
||||
with BaseWidgetProperties {
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
final refreshKey = GlobalKey<RefreshIndicatorState>();
|
||||
|
||||
@ -235,7 +226,6 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> with
|
||||
|
||||
// Refresh the widget - handler for custom request() method
|
||||
Future<void> refresh(BuildContext context) async {
|
||||
|
||||
// Escape if the widget is no longer loaded
|
||||
if (!mounted) {
|
||||
return;
|
||||
@ -259,13 +249,14 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> with
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
// Save the context for future use
|
||||
_context = context;
|
||||
|
||||
List<Widget> tabs = getTabIcons(context);
|
||||
|
||||
Widget body = tabs.isEmpty ? getBody(context) : TabBarView(children: getTabs(context));
|
||||
Widget body = tabs.isEmpty
|
||||
? getBody(context)
|
||||
: TabBarView(children: getTabs(context));
|
||||
|
||||
Scaffold view = Scaffold(
|
||||
key: scaffoldKey,
|
||||
@ -282,19 +273,16 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> with
|
||||
onRefresh: () async {
|
||||
refresh(context);
|
||||
},
|
||||
child: body
|
||||
child: body,
|
||||
),
|
||||
bottomNavigationBar: buildBottomAppBar(context, scaffoldKey),
|
||||
);
|
||||
|
||||
// Default implementation is *not* tabbed
|
||||
if (tabs.isNotEmpty) {
|
||||
return DefaultTabController(
|
||||
length: tabs.length,
|
||||
child: view,
|
||||
);
|
||||
return DefaultTabController(length: tabs.length, child: view);
|
||||
} else {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user