Skip to content

Commit

Permalink
Merge pull request #510 from Guillergood/125-jump-to-letter
Browse files Browse the repository at this point in the history
Jump to Letter when scrolling, closes #125
  • Loading branch information
jmshrv authored Oct 17, 2023
2 parents e607548 + 5ec65b9 commit 56942bc
Show file tree
Hide file tree
Showing 3 changed files with 351 additions and 154 deletions.
71 changes: 71 additions & 0 deletions lib/components/MusicScreen/alphabet_item_list.dart
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));
}
}
Loading

0 comments on commit 56942bc

Please sign in to comment.