Publisher profile basis

This commit is contained in:
2025-05-14 00:49:54 +08:00
parent 610b924daf
commit 70f58259de
8 changed files with 632 additions and 158 deletions

View File

@ -0,0 +1,135 @@
import 'package:auto_route/annotations.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/post.dart';
import 'package:island/pods/network.dart';
import 'package:island/widgets/account/status.dart';
import 'package:island/widgets/app_scaffold.dart';
import 'package:island/widgets/content/cloud_files.dart';
import 'package:island/widgets/post/post_list.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:styled_widget/styled_widget.dart';
part 'pub_profile.g.dart';
@riverpod
Future<SnPublisher> publisher(Ref ref, String uname) async {
final apiClient = ref.watch(apiClientProvider);
final resp = await apiClient.get("/publishers/$uname");
return SnPublisher.fromJson(resp.data);
}
@RoutePage()
class PublisherProfileScreen extends HookConsumerWidget {
final String name;
const PublisherProfileScreen({
super.key,
@PathParam("name") required this.name,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final publisher = ref.watch(publisherProvider(name));
final iconShadow = Shadow(
color: Colors.black54,
blurRadius: 5.0,
offset: Offset(1.0, 1.0),
);
return publisher.when(
data:
(data) => AppScaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: 180,
pinned: true,
leading: PageBackButton(shadows: [iconShadow]),
flexibleSpace: FlexibleSpaceBar(
background:
data.backgroundId != null
? CloudImageWidget(fileId: data.backgroundId!)
: Container(
color:
Theme.of(context).appBarTheme.backgroundColor,
),
title: Text(
data.nick,
style: TextStyle(
color: Theme.of(context).appBarTheme.foregroundColor,
shadows: [iconShadow],
),
),
),
),
SliverToBoxAdapter(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 20,
children: [
ProfilePictureWidget(fileId: data.pictureId!, radius: 32),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
spacing: 6,
children: [
Text(data.nick).fontSize(20),
Text(
'@${data.name}',
).fontSize(14).opacity(0.85),
],
),
if (data.publisherType == 0)
AccountStatusWidget(
uname: name,
padding: EdgeInsets.zero,
),
],
),
),
],
).padding(horizontal: 24, top: 24, bottom: 24),
),
// if (data.badges.isNotEmpty)
// SliverToBoxAdapter(
// child: BadgeList(
// badges: data.badges,
// ).padding(horizontal: 24, bottom: 24),
// )
// else
// const Gap(16),
SliverToBoxAdapter(child: const Divider(height: 1)),
if (data.bio.isNotEmpty)
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [Text('bio').tr().bold(), Text(data.bio)],
).padding(horizontal: 24, top: 24),
),
if (data.bio.isNotEmpty)
SliverToBoxAdapter(
child: const Divider(height: 1).padding(top: 24),
),
SliverPostList(pubName: name),
SliverGap(MediaQuery.of(context).padding.bottom + 16),
],
),
),
error:
(error, stackTrace) => AppScaffold(
appBar: AppBar(leading: const PageBackButton()),
body: Center(child: Text(error.toString())),
),
loading:
() => AppScaffold(
appBar: AppBar(leading: const PageBackButton()),
body: Center(child: CircularProgressIndicator()),
),
);
}
}

View File

@ -0,0 +1,149 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'pub_profile.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$publisherHash() => r'3a7ae4d48765170aea42c7d6f4502d68f984dfab';
/// Copied from Dart SDK
class _SystemHash {
_SystemHash._();
static int combine(int hash, int value) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + value);
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}
static int finish(int hash) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
// ignore: parameter_assignments
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
}
/// See also [publisher].
@ProviderFor(publisher)
const publisherProvider = PublisherFamily();
/// See also [publisher].
class PublisherFamily extends Family<AsyncValue<SnPublisher>> {
/// See also [publisher].
const PublisherFamily();
/// See also [publisher].
PublisherProvider call(String uname) {
return PublisherProvider(uname);
}
@override
PublisherProvider getProviderOverride(covariant PublisherProvider provider) {
return call(provider.uname);
}
static const Iterable<ProviderOrFamily>? _dependencies = null;
@override
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
@override
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
_allTransitiveDependencies;
@override
String? get name => r'publisherProvider';
}
/// See also [publisher].
class PublisherProvider extends AutoDisposeFutureProvider<SnPublisher> {
/// See also [publisher].
PublisherProvider(String uname)
: this._internal(
(ref) => publisher(ref as PublisherRef, uname),
from: publisherProvider,
name: r'publisherProvider',
debugGetCreateSourceHash:
const bool.fromEnvironment('dart.vm.product')
? null
: _$publisherHash,
dependencies: PublisherFamily._dependencies,
allTransitiveDependencies: PublisherFamily._allTransitiveDependencies,
uname: uname,
);
PublisherProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.uname,
}) : super.internal();
final String uname;
@override
Override overrideWith(
FutureOr<SnPublisher> Function(PublisherRef provider) create,
) {
return ProviderOverride(
origin: this,
override: PublisherProvider._internal(
(ref) => create(ref as PublisherRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
uname: uname,
),
);
}
@override
AutoDisposeFutureProviderElement<SnPublisher> createElement() {
return _PublisherProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is PublisherProvider && other.uname == uname;
}
@override
int get hashCode {
var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, uname.hashCode);
return _SystemHash.finish(hash);
}
}
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
mixin PublisherRef on AutoDisposeFutureProviderRef<SnPublisher> {
/// The parameter `uname` of this provider.
String get uname;
}
class _PublisherProviderElement
extends AutoDisposeFutureProviderElement<SnPublisher>
with PublisherRef {
_PublisherProviderElement(super.provider);
@override
String get uname => (origin as PublisherProvider).uname;
}
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package