together_mobile/lib/screens/contact/contact_screen.dart

200 lines
6.1 KiB
Dart
Raw Normal View History

import 'dart:io';
2023-06-21 17:44:28 +08:00
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:together_mobile/utils/init_get_it.dart';
import 'package:together_mobile/models/user_model.dart';
2023-06-21 17:44:28 +08:00
import 'package:together_mobile/screens/contact/components/friend_tile.dart';
import 'package:together_mobile/screens/contact/components/group_chat_tile.dart';
class ContactScreen extends StatefulWidget {
const ContactScreen({super.key});
@override
State<ContactScreen> createState() => _ContactScreenState();
}
class _ContactScreenState extends State<ContactScreen> {
@override
Widget build(BuildContext context) {
// Create a localkey, use to generate the custom scroll view,
// or there will be a error: "Duplicate GlobalKey detected in widget tree."
// But when I wrap custom scroll view into the RefrashIndicator, the key isn't needed any more
// const Key customScrollKey = ValueKey<String>('bottom-sliver-list');
return Scaffold(
appBar: AppBar(
leading: Row(
2023-06-21 17:44:28 +08:00
children: [
const SizedBox(
2023-06-21 17:44:28 +08:00
width: 8,
),
CircleAvatar(
backgroundImage: FileImage(
File(getIt.get<UserProfile>().avatar),
),
2023-06-21 17:44:28 +08:00
),
],
),
title: const Text('通讯录'),
centerTitle: true,
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.search),
splashRadius: 20,
),
IconButton(
onPressed: () {
context.push('/contact/add');
},
icon: const Icon(Icons.person_add_alt_1),
splashRadius: 20,
),
],
),
body: RefreshIndicator(
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2));
},
child: CustomScrollView(
physics: const BouncingScrollPhysics(),
// key: customScrollKey,
slivers: [
SliverFixedExtentList(
delegate: SliverChildListDelegate(
[
TextButton(
onPressed: () {
context.push('/contact/apply_list');
},
style: TextButton.styleFrom(
iconColor: Theme.of(context).textTheme.bodyLarge?.color,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'添加申请',
style: TextStyle(
fontSize: 16,
color:
Theme.of(context).textTheme.bodyLarge?.color,
),
),
const Icon(
Icons.keyboard_arrow_right,
size: 30,
),
],
),
),
TextButton(
onPressed: () {
context.push('/contact/friend_group');
},
style: TextButton.styleFrom(
iconColor: Theme.of(context).textTheme.bodyLarge?.color,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'分组管理',
style: TextStyle(
fontSize: 16,
color:
Theme.of(context).textTheme.bodyLarge?.color,
),
),
const Icon(
Icons.keyboard_arrow_right,
size: 30,
),
],
),
),
],
),
itemExtent: 50.0,
),
const SliverPersistentHeader(
delegate: _MySliverPersistentHeader(),
pinned: true,
),
SliverList(
delegate: SliverChildBuilderDelegate(
(
BuildContext context,
int index,
) =>
const FriendTile(),
childCount: 15,
),
),
],
),
));
}
}
class _MySliverPersistentHeader extends SliverPersistentHeaderDelegate {
const _MySliverPersistentHeader();
@override
double get minExtent => 50;
@override
double get maxExtent => 50;
@override
Widget build(
BuildContext context,
double shrinkOffset,
bool overlapsContent,
) {
return Container(
height: 50,
color: Theme.of(context).colorScheme.background,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {},
child: Text(
'分组',
style: TextStyle(
color: Theme.of(context).textTheme.bodyLarge?.color,
),
),
),
TextButton(
onPressed: () {},
child: Text(
'全部好友',
style: TextStyle(
color: Theme.of(context).textTheme.bodyLarge?.color,
),
),
),
TextButton(
onPressed: () {},
child: Text(
'群聊',
style: TextStyle(
color: Theme.of(context).textTheme.bodyLarge?.color,
),
),
),
],
),
);
}
@override
bool shouldRebuild(covariant _MySliverPersistentHeader oldDelegate) {
return false;
}
}