-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add season filter and improve UI with elevated_dropdown_button.dart
- Loading branch information
Showing
13 changed files
with
413 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ElevatedDropdownButton<T> extends StatelessWidget { | ||
final GlobalKey globalKey; | ||
final T? value; | ||
final List<ElevatedPopupMenuItem<T>> items; | ||
final Function(T) onChanged; | ||
final bool showIcon; | ||
final Widget? child; | ||
|
||
const ElevatedDropdownButton({ | ||
required this.globalKey, | ||
required this.value, | ||
required this.items, | ||
required this.onChanged, | ||
this.showIcon = true, | ||
this.child, | ||
}) : super(key: globalKey); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton( | ||
key: globalKey, | ||
onPressed: () { | ||
final renderBox = | ||
globalKey.currentContext!.findRenderObject() as RenderBox; | ||
// Get position of the season button | ||
final position = renderBox.localToGlobal(Offset.zero); | ||
|
||
showMenu<T>( | ||
context: context, | ||
position: RelativeRect.fromLTRB( | ||
position.dx, | ||
position.dy, | ||
position.dx, | ||
position.dy, | ||
), | ||
items: [...items.map((item) => item.build())], | ||
).then((value) { | ||
if (value != null) { | ||
onChanged(value); | ||
} | ||
}); | ||
}, | ||
child: Flex( | ||
direction: Axis.horizontal, | ||
children: [ | ||
if (child != null) | ||
child! | ||
else | ||
items | ||
.firstWhere( | ||
(item) => item.value == value, | ||
orElse: () => items.first, | ||
) | ||
.child, | ||
if (showIcon) ...[ | ||
const SizedBox(width: 8), | ||
const Icon(Icons.arrow_drop_down), | ||
], | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
class ElevatedPopupMenuItem<T> { | ||
final T value; | ||
final Widget? leading; | ||
final Widget child; | ||
|
||
const ElevatedPopupMenuItem({ | ||
required this.value, | ||
this.leading, | ||
required this.child, | ||
}); | ||
|
||
PopupMenuItem<T> build() { | ||
return PopupMenuItem<T>( | ||
value: value, | ||
child: Row( | ||
children: [ | ||
if (leading != null) leading!, | ||
const SizedBox(width: 8), | ||
child, | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'season_dto.freezed.dart'; | ||
part 'season_dto.g.dart'; | ||
|
||
@freezed | ||
class SeasonDto with _$SeasonDto { | ||
const factory SeasonDto({ | ||
required int number, | ||
required String lastReleaseDateTime, | ||
}) = _SeasonDto; | ||
|
||
factory SeasonDto.fromJson(Map<String, dynamic> json) => | ||
_$SeasonDtoFromJson(json); | ||
} |
Oops, something went wrong.