alphabetical_scroll 0.0.2 alphabetical_scroll: ^0.0.2 copied to clipboard
A Flutter package to achieve alphabet scrolling. Based on flutter_sticky_header.
import 'dart:developer';
import 'package:alphabetical_scroll/alphabetical_scroll.dart';
import 'package:faker/faker.dart';
import 'package:flutter/material.dart';
import 'contact_info.dart';
import 'contact_tile.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<ContactInfo> contacts = [];
List<ContactInfo> contactList = [];
ScrollController scrollController = ScrollController();
@override
void initState() {
super.initState();
var faker = Faker();
for (int i = 0; i < 100; i++) {
if (i < 60) {
contacts.add(ContactInfo(
id: i,
name: faker.person.name(),
bgColor: Colors.blue,
));
// contacts.add(faker.person.name());
}
// else if (i > 60 && i < 90) {
// contacts.add(ContactInfo(
// id: i,
// name: faker.person.firstName(),
// bgColor: Colors.blue,
// ));
// // contacts.add(faker.phoneNumber.us());
// }
else {
contacts.add(ContactInfo(
id: i,
name: faker.phoneNumber.us(),
bgColor: Colors.blue,
));
// contacts.add(faker.phoneNumber.us());
}
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
iconTheme: const IconThemeData(
color: Colors.black,
),
backgroundColor: const Color(0xFFEDEDED),
title: const Text(
'Contacts',
style: TextStyle(color: Color(0xFF171717)),
),
),
body: AlphabetListScreen<ContactInfo>(
itemBuilder: (context, contactInfo) {
return ContactTile(
name: contactInfo.name,
);
},
listScrollController: scrollController,
sources: contacts,
sourceFilterItemList: contacts.map((e) => e.name).toList(),
onTap: (item) {
log("pressed ${item.id} do something");
},
),
),
);
}
}