forked from jmshrv/finamp
-
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.
Merge pull request jmshrv#510 from Guillergood/125-jump-to-letter
Jump to Letter when scrolling, closes jmshrv#125
- Loading branch information
Showing
3 changed files
with
351 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:finamp/models/jellyfin_models.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class AlphabetList extends StatefulWidget { | ||
final Function(String) callback; | ||
|
||
final String sortOrder; | ||
|
||
const AlphabetList({super.key, required this.callback, required this.sortOrder}); | ||
|
||
@override | ||
State<AlphabetList> createState() => _AlphabetListState(); | ||
} | ||
|
||
class _AlphabetListState extends State<AlphabetList> { | ||
List<String> alphabet = ['#'] + | ||
List.generate(26, (int index) { | ||
return String.fromCharCode('A'.codeUnitAt(0) + index); | ||
}); | ||
|
||
|
||
List<String> get getAlphabet => alphabet; | ||
|
||
@override | ||
void initState() { | ||
orderTheList(alphabet); | ||
super.initState(); | ||
} | ||
|
||
|
||
@override | ||
void didUpdateWidget(AlphabetList oldWidget) { | ||
orderTheList(alphabet); | ||
super.didUpdateWidget(oldWidget); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Align( | ||
alignment: Alignment.centerRight, | ||
child: Container( | ||
padding: const EdgeInsets.symmetric(horizontal: 2), | ||
child: SingleChildScrollView( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: List.generate( | ||
alphabet.length, | ||
(x) => InkWell( | ||
onTap: () { | ||
widget.callback(alphabet[x]); | ||
}, | ||
child: Container( | ||
padding: | ||
const EdgeInsets.symmetric(horizontal: 10, vertical: 2), | ||
child: Text( | ||
alphabet[x].toUpperCase(), | ||
), | ||
), | ||
), | ||
)), | ||
), | ||
), | ||
); | ||
} | ||
|
||
void orderTheList(List<String> list) { | ||
widget.sortOrder == "Ascending" | ||
? list.sort() | ||
: list.sort((a, b) => b.compareTo(a)); | ||
} | ||
} |
Oops, something went wrong.