Skip to content

Commit

Permalink
update versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasweigenast committed Jun 30, 2023
1 parent 8d5896e commit d9c6b29
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 136 deletions.
46 changes: 15 additions & 31 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ class MyApp extends StatelessWidget {
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: const ColorScheme.light(
primary: Colors.deepPurple, secondary: Colors.teal),
colorScheme: const ColorScheme.light(primary: Colors.deepPurple, secondary: Colors.teal),
textTheme: GoogleFonts.robotoTextTheme(),
cardTheme: CardTheme(
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
),
popupMenuTheme: PopupMenuThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)))),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)))),
home: const MainView(),
);
}
Expand All @@ -64,8 +61,7 @@ const kCustomPagedDataTableTheme = PagedDataTableThemeData(
headerBackgroundColor: Color(0xFF80CBC4),
filtersHeaderBackgroundColor: Color(0xFF80CBC4),
footerBackgroundColor: Color(0xFF80CBC4),
textStyle: TextStyle(
decoration: TextDecoration.underline, fontWeight: FontWeight.normal),
textStyle: TextStyle(decoration: TextDecoration.underline, fontWeight: FontWeight.normal),
rowsTextStyle: TextStyle(decoration: TextDecoration.overline),
buttonsColor: Colors.white,
chipTheme: ChipThemeData(
Expand Down Expand Up @@ -112,8 +108,7 @@ class _MainViewState extends State<MainView> {
cellBuilder: (item) => Text(item.id.toString()),
sizeFactor: .05,
),
TableColumn(
title: "Author", cellBuilder: (item) => Text(item.author)),
TableColumn(title: "Author", cellBuilder: (item) => Text(item.author)),
LargeTextTableColumn(
title: "Content",
getter: (post) => post.content,
Expand All @@ -127,8 +122,7 @@ class _MainViewState extends State<MainView> {
id: "createdAt",
title: "Created At",
sortable: true,
cellBuilder: (item) =>
Text(DateFormat.yMd().format(item.createdAt))),
cellBuilder: (item) => Text(DateFormat.yMd().format(item.createdAt))),
DropdownTableColumn<Post, Gender>(
title: "Gender",
sizeFactor: null,
Expand All @@ -141,13 +135,10 @@ class _MainViewState extends State<MainView> {
items: const [
DropdownMenuItem(value: Gender.male, child: Text("Male")),
DropdownMenuItem(value: Gender.female, child: Text("Female")),
DropdownMenuItem(
value: Gender.unespecified, child: Text("Unspecified")),
DropdownMenuItem(value: Gender.unespecified, child: Text("Unspecified")),
],
),
TableColumn(
title: "Enabled",
cellBuilder: (item) => Text(item.isEnabled ? "Yes" : "No")),
TableColumn(title: "Enabled", cellBuilder: (item) => Text(item.isEnabled ? "Yes" : "No")),
TextTableColumn(
title: "Number",
id: "number",
Expand All @@ -171,26 +162,20 @@ class _MainViewState extends State<MainView> {
return true;
}),
TableColumn(
title: "Fixed Value",
cellBuilder: (item) => const Text("abc"),
sizeFactor: null),
title: "Fixed Value", cellBuilder: (item) => const Text("abc"), sizeFactor: null),
],
filters: [
TextTableFilter(
id: "authorName",
title: "Author's name",
chipFormatter: (text) => "By $text"),
id: "authorName", title: "Author's name", chipFormatter: (text) => "By $text"),
DropdownTableFilter<Gender>(
id: "gender",
title: "Gender",
defaultValue: Gender.male,
chipFormatter: (gender) =>
'Only ${gender.name.toLowerCase()} posts',
chipFormatter: (gender) => 'Only ${gender.name.toLowerCase()} posts',
items: const [
DropdownMenuItem(value: Gender.male, child: Text("Male")),
DropdownMenuItem(value: Gender.female, child: Text("Female")),
DropdownMenuItem(
value: Gender.unespecified, child: Text("Unspecified")),
DropdownMenuItem(value: Gender.unespecified, child: Text("Unspecified")),
]),
DatePickerTableFilter(
id: "date",
Expand Down Expand Up @@ -250,8 +235,7 @@ class _MainViewState extends State<MainView> {
var selectedPosts = tableController.getSelectedRows();
debugPrint("SELECTED ROWS ----------------------------");
debugPrint(selectedPosts
.map((e) =>
"Id [${e.id}] Author [${e.author}] Gender [${e.authorGender.name}]")
.map((e) => "Id [${e.id}] Author [${e.author}] Gender [${e.authorGender.name}]")
.join("\n"));
debugPrint("------------------------------------------");
}),
Expand All @@ -263,8 +247,8 @@ class _MainViewState extends State<MainView> {
FilterMenuItem(
title: const Text("Select random row"),
onTap: () {
tableController.selectRow(
Random(DateTime.now().microsecondsSinceEpoch).nextInt(10));
tableController
.selectRow(Random(DateTime.now().microsecondsSinceEpoch).nextInt(10));
}),
const FilterMenuDivider(),
FilterMenuItem(
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: calendar_date_picker2
sha256: "3771315053090c8e2b4b7941076f8e2c1e396ef1a5a5cb5014b281d8e090e348"
sha256: f7ecd632260f2af6cfb72f6b7878f847b0a61821d50f26df9bd00b0a336d0cac
url: "https://pub.dev"
source: hosted
version: "0.3.7"
version: "0.5.2"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -114,10 +114,10 @@ packages:
dependency: transitive
description:
name: flutter_hooks
sha256: "2b202559a4ed3656bbb7aae9d8b335fb0037b23acc7ae3f377d1ba0b95c21aec"
sha256: "6a126f703b89499818d73305e4ce1e3de33b4ae1c5512e3b8eab4b986f46774c"
url: "https://pub.dev"
source: hosted
version: "0.18.5+1"
version: "0.18.6"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: paged_datatable_example
description: A new Flutter project.

publish_to: 'none'
publish_to: "none"
version: 1.0.0+1

environment:
sdk: ">=2.19.0 <3.0.0"
sdk: ">=2.19.0 <4.0.0"

dependencies:
paged_datatable:
Expand All @@ -26,4 +26,4 @@ dev_dependencies:
flutter_lints: ^1.0.0

flutter:
uses-material-design: true
uses-material-design: true
17 changes: 6 additions & 11 deletions lib/src/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,12 @@ class _DateTimeRangePicker extends HookWidget {
);
}

String _format(
DateFormat dateFormat, ObjectRef<DateTimeRange?> currentValueRef) {
String _format(DateFormat dateFormat, ObjectRef<DateTimeRange?> currentValueRef) {
return "${dateFormat.format(currentValueRef.value!.start)} - ${dateFormat.format(currentValueRef.value!.end)}";
}
}

class _DropdownButtonCell<TType extends Object, T extends Object>
extends HookWidget {
class _DropdownButtonCell<TType extends Object, T extends Object> extends HookWidget {
final T? initialValue;
final List<DropdownMenuItem<T>> items;
final InputDecoration? decoration;
Expand Down Expand Up @@ -153,8 +151,7 @@ class _DropdownButtonCell<TType extends Object, T extends Object>
child: DropdownButtonFormField<T>(
focusNode: focusNode,
items: items,
decoration:
decoration ?? const InputDecoration(border: InputBorder.none),
decoration: decoration ?? const InputDecoration(border: InputBorder.none),
value: currentValueRef.value,
onChanged: isLoadingN.value
? null
Expand Down Expand Up @@ -337,19 +334,17 @@ class _EditableTextField extends HookWidget {
},
child: isLoadingN.value
? const SizedBox(
child: CircularProgressIndicator(),
height: 20,
width: 20,
child: CircularProgressIndicator(),
)
: (tooltipText
? Tooltip(
message: currentValueRef.value,
margin: tooltipMargin,
padding: tooltipPadding,
child: Text(currentValueRef.value,
overflow: TextOverflow.ellipsis))
: Text(currentValueRef.value,
overflow: TextOverflow.ellipsis)));
child: Text(currentValueRef.value, overflow: TextOverflow.ellipsis))
: Text(currentValueRef.value, overflow: TextOverflow.ellipsis)));
}
}

Expand Down
26 changes: 7 additions & 19 deletions lib/src/paged_datatable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ part 'types.dart';
/// A paginated DataTable that allows page caching and filtering
/// [TKey] is the type of the page token
/// [TResult] is the type of data the data table will show.
class PagedDataTable<TKey extends Object, TResult extends Object>
extends StatelessWidget {
class PagedDataTable<TKey extends Object, TResult extends Object> extends StatelessWidget {
final FetchCallback<TKey, TResult> fetchPage;
final TKey initialPage;
final List<TableFilter>? filters;
Expand Down Expand Up @@ -76,9 +75,8 @@ class PagedDataTable<TKey extends Object, TResult extends Object>
refreshListener: refreshListener),
builder: (context, widget) {
var state = context.read<_PagedDataTableState<TKey, TResult>>();
final localTheme = PagedDataTableTheme.maybeOf(context) ??
theme ??
_kDefaultPagedDataTableTheme;
final localTheme =
PagedDataTableTheme.maybeOf(context) ?? theme ?? _kDefaultPagedDataTableTheme;

Widget child = Material(
color: localTheme.backgroundColor,
Expand All @@ -91,9 +89,7 @@ class PagedDataTable<TKey extends Object, TResult extends Object>
return Column(
children: [
/* FILTER TAB */
if (header != null ||
menu != null ||
state.filters.isNotEmpty) ...[
if (header != null || menu != null || state.filters.isNotEmpty) ...[
_PagedDataTableFilterTab<TKey, TResult>(menu, header),
Divider(height: 0, color: localTheme.dividerColor),
],
Expand All @@ -105,11 +101,7 @@ class PagedDataTable<TKey extends Object, TResult extends Object>
/* ITEMS */
Expanded(
child: _PagedDataTableRows<TKey, TResult>(
rowsSelectable,
customRowBuilder,
noItemsFoundBuilder,
errorBuilder,
width),
rowsSelectable, customRowBuilder, noItemsFoundBuilder, errorBuilder, width),
),

/* FOOTER */
Expand All @@ -123,14 +115,10 @@ class PagedDataTable<TKey extends Object, TResult extends Object>
// apply configuration to this widget only
if (theme != null) {
child = PagedDataTableTheme(data: theme!, child: child);
assert(
theme!.rowColors != null ? theme!.rowColors!.length == 2 : true,
assert(theme!.rowColors != null ? theme!.rowColors!.length == 2 : true,
"rowColors must contain exactly two colors");
} else {
assert(
localTheme.rowColors != null
? localTheme.rowColors!.length == 2
: true,
assert(localTheme.rowColors != null ? localTheme.rowColors!.length == 2 : true,
"rowColors must contain exactly two colors");
}

Expand Down
27 changes: 10 additions & 17 deletions lib/src/paged_datatable_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ class _PagedDataTableMenu extends StatelessWidget {
}
}

void _showMenu(
{required BuildContext context, required List<BaseFilterMenuItem> items}) {
void _showMenu({required BuildContext context, required List<BaseFilterMenuItem> items}) {
final RenderBox button = context.findRenderObject() as RenderBox;
var offset = button.localToGlobal(Offset.zero);
var position = RelativeRect.fromLTRB(
offset.dx + 10, offset.dy + button.size.height - 10, 0, 0);
var position = RelativeRect.fromLTRB(offset.dx + 10, offset.dy + button.size.height - 10, 0, 0);

// var rect = RelativeRect.fromLTRB(offset.dx + 10, offset.dy + size.height - 10, 0, 0);

Expand All @@ -47,10 +45,8 @@ void _showMenu(
_PopupMenuRoute(
items: items,
position: position,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
capturedThemes:
InheritedTheme.capture(from: context, to: navigator.context)));
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
capturedThemes: InheritedTheme.capture(from: context, to: navigator.context)));
}

class _PopupMenuRoute<T> extends PopupRoute<T> {
Expand Down Expand Up @@ -98,8 +94,8 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
final String barrierLabel;

@override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
Widget buildPage(
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
final menu = _PagedDataTableMenu(items: items);
final MediaQueryData mediaQuery = MediaQuery.of(context);
return MediaQuery.removePadding(
Expand Down Expand Up @@ -166,14 +162,12 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {

if (x < _kMenuScreenPadding + padding.left) {
x = _kMenuScreenPadding + padding.left;
} else if (x + childSize.width >
size.width - _kMenuScreenPadding - padding.right) {
} else if (x + childSize.width > size.width - _kMenuScreenPadding - padding.right) {
x = size.width - childSize.width - _kMenuScreenPadding - padding.right;
}
if (y < _kMenuScreenPadding + padding.top) {
y = _kMenuScreenPadding + padding.top;
} else if (y + childSize.height >
size.height - _kMenuScreenPadding - padding.bottom) {
} else if (y + childSize.height > size.height - _kMenuScreenPadding - padding.bottom) {
y = size.height - padding.bottom - _kMenuScreenPadding - childSize.height;
}

Expand Down Expand Up @@ -207,8 +201,7 @@ class _AutoAnimatedSize extends StatefulWidget {
State<StatefulWidget> createState() => _AutoAnimatedSizeState();
}

class _AutoAnimatedSizeState extends State<_AutoAnimatedSize>
with SingleTickerProviderStateMixin {
class _AutoAnimatedSizeState extends State<_AutoAnimatedSize> with SingleTickerProviderStateMixin {
bool showChild = false;

@override
Expand All @@ -224,9 +217,9 @@ class _AutoAnimatedSizeState extends State<_AutoAnimatedSize>
Widget build(BuildContext context) {
return AnimatedSize(
alignment: widget.alignment,
child: showChild ? widget.child : const SizedBox(width: 1, height: 1),
curve: Curves.fastLinearToSlowEaseIn,
duration: const Duration(milliseconds: 300),
child: showChild ? widget.child : const SizedBox(width: 1, height: 1),
);
}
}
Loading

0 comments on commit d9c6b29

Please sign in to comment.