Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to add a custom loading indicator #102

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dart.lineLength": 80,
"files.eol": "\n",
}
}
3 changes: 3 additions & 0 deletions demo/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:demo/screen/feature/custom_loading_indicator_screen.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -110,6 +111,8 @@ class MyApp extends StatelessWidget {
const TimeTypeColumnScreen(),
ValueFormatterScreen.routeName: (context) =>
const ValueFormatterScreen(),
CustomLoadingIndicatorScreen.routeName: (context) =>
const CustomLoadingIndicatorScreen(),
// only development
EmptyScreen.routeName: (context) => const EmptyScreen(),
DevelopmentScreen.routeName: (context) => const DevelopmentScreen(),
Expand Down
139 changes: 139 additions & 0 deletions demo/lib/screen/feature/custom_loading_indicator_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import 'package:flutter/material.dart';
import 'package:pluto_grid_plus/pluto_grid_plus.dart';

import '../../dummy_data/development.dart';

class CustomLoadingIndicatorScreen extends StatefulWidget {
static const routeName = 'feature/custom-loading-indicator';

const CustomLoadingIndicatorScreen({super.key});

@override
_CustomLoadingIndicatorScreenState createState() => _CustomLoadingIndicatorScreenState();
}

class _CustomLoadingIndicatorScreenState extends State<CustomLoadingIndicatorScreen> {
late List<PlutoColumn> columns;

late List<PlutoRow> rows;

PlutoGridStateManager? stateManager;

@override
void initState() {
super.initState();

columns = [
PlutoColumn(
title: 'column1',
field: 'column1',
type: PlutoColumnType.text(),
),
PlutoColumn(
title: 'column2',
field: 'column2',
type: PlutoColumnType.text(),
),
PlutoColumn(
title: 'column3',
field: 'column3',
type: PlutoColumnType.text(),
),
];

rows = DummyData.rowsByColumns(length: 10, columns: columns);
}

@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: Listenable.merge([stateManager]),
builder: (context, child) {
return Scaffold(
appBar: AppBar(
title: const Text('Custom Loading Indicator'),
actions: PlutoGridLoadingLevel.values.map((level) {
if (stateManager == null) return SizedBox.shrink();

return Padding(
padding: const EdgeInsets.all(8),
child: GestureDetector(
onTap: () => stateManager?.setLoadingLevel(level),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: stateManager?.loadingLevel == level
? Theme.of(context).colorScheme.primary
: Colors.transparent),
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.all(8),
child: Text(level.name),
),
),
),
);
}).toList(),
),
persistentFooterButtons: [
TextButton(
onPressed: () {
stateManager?.setShowLoading(stateManager?.showLoading == false,
level: stateManager!.loadingLevel);
},
child: const Text('Toggle Loading'),
)
],
body: SafeArea(
child: Container(
padding: const EdgeInsets.all(8),
child: PlutoGrid(
columns: columns,
rows: rows,
mode: PlutoGridMode.readOnly,
onChanged: (PlutoGridOnChangedEvent event) {
print(event);
},
onLoaded: (PlutoGridOnLoadedEvent event) {
setState(() => stateManager = event.stateManager);

stateManager?.setCustomLoadingIndicator(
(context) => CustomLoadingIndicator());
},
configuration: const PlutoGridConfiguration(
columnSize: PlutoGridColumnSizeConfig(
autoSizeMode: PlutoAutoSizeMode.scale)),
),
),
),
);
},
);
}
}

class CustomLoadingIndicator extends StatefulWidget {
const CustomLoadingIndicator({super.key});

@override
State<CustomLoadingIndicator> createState() => _CustomLoadingIndicatorState();
}

class _CustomLoadingIndicatorState extends State<CustomLoadingIndicator> {
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned.fill(
child: ColoredBox(
color:
Theme.of(context).colorScheme.onPrimary.withValues(alpha: .6),
),
),
Center(child: CircularProgressIndicator.adaptive()),
],
);
}
}
17 changes: 16 additions & 1 deletion demo/lib/screen/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:math';

import 'package:demo/screen/empty_screen.dart';
import 'package:demo/screen/feature/custom_loading_indicator_screen.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

Expand Down Expand Up @@ -492,6 +492,14 @@ class PlutoFeatures extends StatelessWidget {
Navigator.pushNamed(context, DarkModeScreen.routeName);
},
),
PlutoListTile(
title: 'Custom Loading Indicator',
description: 'Define a custom loading indicator.',
onTapLiveDemo: () {
Navigator.pushNamed(
context, CustomLoadingIndicatorScreen.routeName);
},
),
PlutoListTile.amber(
title: 'Empty',
description:
Expand Down Expand Up @@ -713,6 +721,13 @@ class PlutoContributors extends StatelessWidget {
launchUrl('https://github.com/coruscant187');
},
),
PlutoContributorTile(
name: 'sten435',
linkTitle: 'Github',
onTapLink: () {
launchUrl('https://github.com/sten435');
},
),
PlutoContributorTile.invisible(
name: 'And you.',
linkTitle: 'Github',
Expand Down
2 changes: 1 addition & 1 deletion demo/linux/flutter/ephemeral/.plugin_symlinks/file_saver
2 changes: 1 addition & 1 deletion demo/linux/flutter/ephemeral/.plugin_symlinks/printing
45 changes: 22 additions & 23 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,29 +170,28 @@ class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
body: Container(
padding: const EdgeInsets.all(15),
child: PlutoGrid(
columns: columns,
rows: rows,
columnGroups: columnGroups,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
stateManager.setShowColumnFilter(true);
},
onChanged: (PlutoGridOnChangedEvent event) {
print(event);
},
configuration: const PlutoGridConfiguration(),
selectDateCallback: (PlutoCell cell, PlutoColumn column) async {
return showDatePicker(
context: context,
initialDate: PlutoDateTimeHelper.parseOrNullWithFormat(
cell.value,
column.type.date.format,
) ?? DateTime.now(),
firstDate: column.type.date.startDate ?? DateTime(0),
lastDate: column.type.date.endDate ?? DateTime(9999)
);
}
),
columns: columns,
rows: rows,
columnGroups: columnGroups,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
stateManager.setShowColumnFilter(true);
},
onChanged: (PlutoGridOnChangedEvent event) {
print(event);
},
configuration: const PlutoGridConfiguration(),
selectDateCallback: (PlutoCell cell, PlutoColumn column) async {
return showDatePicker(
context: context,
initialDate: PlutoDateTimeHelper.parseOrNullWithFormat(
cell.value,
column.type.date.format,
) ??
DateTime.now(),
firstDate: column.type.date.startDate ?? DateTime(0),
lastDate: column.type.date.endDate ?? DateTime(9999));
}),
),
);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/helper/show_column_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ List<PopupMenuEntry<PlutoGridColumnMenuItem>> _getDefaultColumnMenuItems({
}) {
final Color textColor = stateManager.style.cellTextStyle.color!;

final Color disableTextColor = textColor.withAlpha((0.5 * 255).toInt());
final Color disableTextColor = textColor.withValues(alpha: 0.5);


final bool enoughFrozenColumnsWidth = stateManager.enoughFrozenColumnsWidth(
stateManager.maxWidth! - column.width,
Expand Down Expand Up @@ -182,7 +183,7 @@ PopupMenuItem<PlutoGridColumnMenuItem> _buildMenuItem<PlutoGridColumnMenuItem>({
child: Text(
text,
style: TextStyle(
color: enabled ? textColor : textColor!.withAlpha((0.5 * 255).toInt()),
color: enabled ? textColor : textColor!.withValues(alpha: 0.5),
fontSize: 13,
),
),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/manager/event/pluto_grid_row_hover_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class PlutoGridRowHoverEvent extends PlutoGridEvent {

@override
void handler(PlutoGridStateManager stateManager) {
bool enableRowHoverColor = stateManager.configuration.style.enableRowHoverColor;
bool enableRowHoverColor =
stateManager.configuration.style.enableRowHoverColor;

// only change current hovered row index
// if row hover color effect is enabled
Expand Down
12 changes: 7 additions & 5 deletions lib/src/manager/shortcut/pluto_grid_shortcut_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,14 @@ class PlutoGridActionPasteValues extends PlutoGridShortcutAction {
return;
}

Clipboard.getData('text/plain').then((value) {
if (value == null) {
return;
}
Clipboard.getData('text/plain').then((ClipboardData? data) {
final text = data?.text;

if (text == null) return;

List<List<String>> textList =
PlutoClipboardTransformation.stringToList(value.text!);
PlutoClipboardTransformation.stringToList(text);


stateManager.pasteCellValue(textList);
});
Expand Down
12 changes: 4 additions & 8 deletions lib/src/manager/state/hovering_state.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import 'package:pluto_grid_plus/pluto_grid_plus.dart';

abstract class IHoveringState {

int? get hoveredRowIdx;

void setHoveredRowIdx(
int? rowIdx,
{bool notify = true}
);
void setHoveredRowIdx(int? rowIdx, {bool notify = true});

bool isRowIdxHovered(int rowIdx);
}
Expand All @@ -24,9 +20,9 @@ mixin HoveringState implements IPlutoGridState {

@override
void setHoveredRowIdx(
int? rowIdx,
{bool notify = true,}
) {
int? rowIdx, {
bool notify = true,
}) {
if (hoveredRowIdx == rowIdx) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/manager/state/layout_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ abstract class ILayoutState {

PlutoGridLoadingLevel get loadingLevel;

WidgetBuilder? get customLoadingIndicator;

bool get hasLeftFrozenColumns;

bool get hasRightFrozenColumns;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/plugin/pluto_infinity_scroll_rows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class _PlutoInfinityScrollRowsState extends State<PlutoInfinityScrollRows> {
if (!_isLast) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (scroll.hasClients && scroll.position.maxScrollExtent == 0) {
var lastRow = stateManager.rows.isNotEmpty ? stateManager.rows.last : null;
var lastRow =
stateManager.rows.isNotEmpty ? stateManager.rows.last : null;
_update(lastRow);
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/plugin/pluto_lazy_pagination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class _PlutoLazyPaginationState extends State<PlutoLazyPagination> {
),
)
.then((data) {
if(!mounted)return;
if (!mounted) return;
stateManager.scroll.bodyRowsVertical!.jumpTo(0);

stateManager.refRows.clearFromOriginal();
Expand Down
Loading
Loading