mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
161
lib/screens/login/widgets/discover_servers_widget.dart
Normal file
161
lib/screens/login/widgets/discover_servers_widget.dart
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
import 'package:ficonsax/ficonsax.dart';
|
||||
import 'package:fladder/models/credentials_model.dart';
|
||||
import 'package:fladder/providers/discovery_provider.dart';
|
||||
import 'package:fladder/util/list_padding.dart';
|
||||
import 'package:fladder/util/localization_helper.dart';
|
||||
import 'package:fladder/util/theme_extensions.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
class DiscoverServersWidget extends ConsumerWidget {
|
||||
final List<CredentialsModel> serverCredentials;
|
||||
final Function(DiscoveryInfo server) onPressed;
|
||||
const DiscoverServersWidget({
|
||||
required this.serverCredentials,
|
||||
required this.onPressed,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final existingServers = serverCredentials
|
||||
.map(
|
||||
(credentials) => DiscoveryInfo(
|
||||
id: credentials.serverId,
|
||||
name: credentials.serverName,
|
||||
address: credentials.server,
|
||||
endPointAddress: null),
|
||||
)
|
||||
.toSet()
|
||||
.toList();
|
||||
final discoverdServersStream = ref.watch(serverDiscoveryProvider);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(6),
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
if (existingServers.isNotEmpty) ...[
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
context.localized.saved,
|
||||
style: context.textTheme.bodyLarge,
|
||||
),
|
||||
const Spacer(),
|
||||
Opacity(opacity: 0.65, child: Icon(IconsaxOutline.bookmark, size: 16)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
...existingServers
|
||||
.map(
|
||||
(server) => _ServerInfoCard(
|
||||
server: server,
|
||||
onPressed: onPressed,
|
||||
),
|
||||
)
|
||||
.toList()
|
||||
.addInBetween(const SizedBox(height: 4)),
|
||||
const Divider(),
|
||||
],
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
context.localized.discovered,
|
||||
style: context.textTheme.bodyLarge,
|
||||
),
|
||||
const Spacer(),
|
||||
Opacity(opacity: 0.65, child: Icon(IconsaxBold.airdrop, size: 16)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
discoverdServersStream.when(
|
||||
data: (data) {
|
||||
final servers = data.where((discoverdServer) => !existingServers.contains(discoverdServer));
|
||||
return servers.isNotEmpty
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...servers.map(
|
||||
(serverInfo) => _ServerInfoCard(
|
||||
server: serverInfo,
|
||||
onPressed: onPressed,
|
||||
),
|
||||
)
|
||||
].toList().addInBetween(const SizedBox(height: 4)),
|
||||
)
|
||||
: Center(
|
||||
child: Opacity(
|
||||
opacity: 0.65,
|
||||
child: Text(
|
||||
context.localized.noServersFound,
|
||||
style: context.textTheme.bodyLarge,
|
||||
),
|
||||
));
|
||||
},
|
||||
error: (error, stackTrace) => Text(context.localized.error),
|
||||
loading: () => Center(
|
||||
child: SizedBox.square(
|
||||
dimension: 24.0,
|
||||
child: CircularProgressIndicator.adaptive(strokeCap: StrokeCap.round),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ServerInfoCard extends StatelessWidget {
|
||||
final Function(DiscoveryInfo server) onPressed;
|
||||
final DiscoveryInfo server;
|
||||
const _ServerInfoCard({
|
||||
required this.server,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: InkWell(
|
||||
onTap: () => onPressed(server),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Card(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
IconsaxBold.driver,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
server.name,
|
||||
style: context.textTheme.bodyLarge,
|
||||
),
|
||||
Opacity(
|
||||
opacity: 0.6,
|
||||
child: Text(
|
||||
server.address,
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(IconsaxOutline.edit_2, size: 16)
|
||||
].addInBetween(const SizedBox(width: 12)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
97
lib/screens/login/widgets/login_icon.dart
Normal file
97
lib/screens/login/widgets/login_icon.dart
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
import 'package:fladder/models/account_model.dart';
|
||||
import 'package:fladder/screens/shared/flat_button.dart';
|
||||
import 'package:fladder/screens/shared/user_icon.dart';
|
||||
import 'package:fladder/util/list_padding.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
class LoginIcon extends ConsumerWidget {
|
||||
final AccountModel user;
|
||||
final Function()? onPressed;
|
||||
final Function()? onLongPress;
|
||||
final Function()? onNewPressed;
|
||||
const LoginIcon({
|
||||
required this.user,
|
||||
this.onPressed,
|
||||
this.onLongPress,
|
||||
this.onNewPressed,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return AspectRatio(
|
||||
aspectRatio: 1.0,
|
||||
child: Card(
|
||||
elevation: 1,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
margin: EdgeInsets.zero,
|
||||
child: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: UserIcon(
|
||||
labelStyle: Theme.of(context).textTheme.displayMedium,
|
||||
size: const Size(125, 125),
|
||||
user: user,
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (onNewPressed != null)
|
||||
Icon(
|
||||
user.authMethod.icon,
|
||||
size: 26,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
user.name,
|
||||
maxLines: 2,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
softWrap: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (user.credentials.serverName.isNotEmpty)
|
||||
Flexible(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.dns_rounded,
|
||||
size: 14,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
user.credentials.serverName,
|
||||
maxLines: 2,
|
||||
softWrap: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
].addInBetween(SizedBox(width: 8, height: 8)),
|
||||
),
|
||||
),
|
||||
FlatButton(
|
||||
onTap: onPressed,
|
||||
onLongPress: onLongPress,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue