2024-05-23 13:12:47 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-25 16:11:00 +00:00
|
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/models/channel.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
2024-06-01 12:18:25 +00:00
|
|
|
import 'package:solian/providers/content/call.dart';
|
2024-05-25 16:11:00 +00:00
|
|
|
import 'package:solian/providers/content/channel.dart';
|
|
|
|
import 'package:solian/router.dart';
|
|
|
|
import 'package:solian/screens/account/notification.dart';
|
|
|
|
import 'package:solian/theme.dart';
|
2024-05-28 12:13:36 +00:00
|
|
|
import 'package:solian/widgets/account/signin_required_overlay.dart';
|
2024-06-22 15:59:11 +00:00
|
|
|
import 'package:solian/widgets/app_bar_title.dart';
|
2024-05-29 15:22:24 +00:00
|
|
|
import 'package:solian/widgets/channel/channel_list.dart';
|
2024-06-01 12:18:25 +00:00
|
|
|
import 'package:solian/widgets/chat/call/chat_call_indicator.dart';
|
2024-06-06 12:23:50 +00:00
|
|
|
import 'package:solian/widgets/current_state_action.dart';
|
2024-05-23 13:12:47 +00:00
|
|
|
|
2024-05-25 16:11:00 +00:00
|
|
|
class ContactScreen extends StatefulWidget {
|
2024-05-23 13:12:47 +00:00
|
|
|
const ContactScreen({super.key});
|
|
|
|
|
2024-05-25 16:11:00 +00:00
|
|
|
@override
|
|
|
|
State<ContactScreen> createState() => _ContactScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ContactScreenState extends State<ContactScreen> {
|
|
|
|
bool _isBusy = true;
|
2024-05-28 16:14:41 +00:00
|
|
|
int? _accountId;
|
2024-05-25 16:11:00 +00:00
|
|
|
|
|
|
|
final List<Channel> _channels = List.empty(growable: true);
|
|
|
|
|
2024-05-28 16:14:41 +00:00
|
|
|
getProfile() async {
|
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
final prof = await auth.getProfile();
|
|
|
|
_accountId = prof.body['id'];
|
|
|
|
}
|
|
|
|
|
2024-05-25 16:11:00 +00:00
|
|
|
getChannels() async {
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
|
|
|
|
final ChannelProvider provider = Get.find();
|
|
|
|
final resp = await provider.listAvailableChannel();
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_channels.clear();
|
|
|
|
_channels.addAll(
|
|
|
|
resp.body.map((e) => Channel.fromJson(e)).toList().cast<Channel>(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
2024-05-28 16:14:41 +00:00
|
|
|
getProfile();
|
2024-05-25 16:11:00 +00:00
|
|
|
getChannels();
|
|
|
|
}
|
|
|
|
|
2024-05-23 13:12:47 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-25 16:11:00 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
2024-06-01 12:18:25 +00:00
|
|
|
final ChatCallProvider call = Get.find();
|
2024-05-25 16:11:00 +00:00
|
|
|
|
2024-05-23 13:12:47 +00:00
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2024-05-28 12:13:36 +00:00
|
|
|
child: FutureBuilder(
|
2024-05-28 14:13:23 +00:00
|
|
|
future: auth.isAuthorized,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
} else if (snapshot.data == false) {
|
|
|
|
return SigninRequiredOverlay(
|
|
|
|
onSignedIn: () {
|
|
|
|
getChannels();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2024-05-28 12:13:36 +00:00
|
|
|
|
2024-05-29 12:13:53 +00:00
|
|
|
return RefreshIndicator(
|
|
|
|
onRefresh: () => getChannels(),
|
|
|
|
child: CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverAppBar(
|
2024-06-22 15:59:11 +00:00
|
|
|
title: AppBarTitle('contact'.tr),
|
2024-05-29 12:13:53 +00:00
|
|
|
centerTitle: false,
|
2024-06-22 15:59:11 +00:00
|
|
|
floating: true,
|
|
|
|
titleSpacing: SolianTheme.titleSpacing(context),
|
|
|
|
toolbarHeight: SolianTheme.toolbarHeight(context),
|
2024-05-29 12:13:53 +00:00
|
|
|
actions: [
|
2024-06-06 12:23:50 +00:00
|
|
|
const BackgroundStateWidget(),
|
2024-05-29 12:13:53 +00:00
|
|
|
const NotificationButton(),
|
|
|
|
PopupMenuButton(
|
|
|
|
icon: const Icon(Icons.add_circle),
|
|
|
|
itemBuilder: (BuildContext context) => [
|
|
|
|
PopupMenuItem(
|
|
|
|
child: ListTile(
|
|
|
|
title: Text('channelOrganizeCommon'.tr),
|
|
|
|
leading: const Icon(Icons.tag),
|
|
|
|
contentPadding:
|
|
|
|
const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
AppRouter.instance
|
|
|
|
.pushNamed('channelOrganizing')
|
|
|
|
.then(
|
|
|
|
(value) {
|
|
|
|
if (value != null) getChannels();
|
2024-05-28 14:13:23 +00:00
|
|
|
},
|
2024-05-29 12:13:53 +00:00
|
|
|
);
|
|
|
|
},
|
2024-05-28 14:13:23 +00:00
|
|
|
),
|
2024-05-29 12:13:53 +00:00
|
|
|
PopupMenuItem(
|
|
|
|
child: ListTile(
|
|
|
|
title: Text('channelOrganizeDirect'.tr),
|
|
|
|
leading: const FaIcon(
|
|
|
|
FontAwesomeIcons.userGroup,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
contentPadding:
|
|
|
|
const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
final ChannelProvider provider = Get.find();
|
|
|
|
provider
|
|
|
|
.createDirectChannel(context, 'global')
|
|
|
|
.then((resp) {
|
|
|
|
if (resp != null) {
|
|
|
|
getChannels();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2024-05-28 14:13:23 +00:00
|
|
|
),
|
|
|
|
],
|
2024-05-25 16:11:00 +00:00
|
|
|
),
|
2024-05-29 12:13:53 +00:00
|
|
|
SizedBox(
|
|
|
|
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
2024-05-28 14:13:23 +00:00
|
|
|
),
|
|
|
|
],
|
2024-05-25 16:11:00 +00:00
|
|
|
),
|
2024-06-01 12:18:25 +00:00
|
|
|
Obx(() {
|
|
|
|
if (call.current.value != null) {
|
|
|
|
return const SliverToBoxAdapter(
|
|
|
|
child: ChatCallCurrentIndicator(),
|
|
|
|
);
|
|
|
|
} else {
|
2024-06-01 16:39:50 +00:00
|
|
|
return const SliverToBoxAdapter();
|
2024-06-01 12:18:25 +00:00
|
|
|
}
|
|
|
|
}),
|
2024-05-29 12:13:53 +00:00
|
|
|
if (_isBusy)
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: const LinearProgressIndicator().animate().scaleX(),
|
|
|
|
),
|
2024-05-29 15:22:24 +00:00
|
|
|
ChannelListWidget(channels: _channels, selfId: _accountId ?? 0),
|
2024-05-29 12:13:53 +00:00
|
|
|
],
|
2024-05-28 14:13:23 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2024-05-23 13:12:47 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|