Compare commits
No commits in common. "3d15c0b9f9aae34b838bd153f9c5e9daffe19eec" and "85d2eff7f8324599e3db9377d0d8a1803c0aee3f" have entirely different histories.
3d15c0b9f9
...
85d2eff7f8
@ -1,41 +0,0 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
const List<int> kExperienceToLevelRequirements = [
|
||||
0, // Level 0
|
||||
1000, // Level 1
|
||||
4000, // Level 2
|
||||
9000, // Level 3
|
||||
16000, // Level 4
|
||||
25000, // Level 5
|
||||
36000, // Level 6
|
||||
49000, // Level 7
|
||||
64000, // Level 8
|
||||
81000, // Level 9
|
||||
100000, // Level 10
|
||||
121000, // Level 11
|
||||
144000, // Level 12
|
||||
368000 // Level 13
|
||||
];
|
||||
|
||||
int getLevelFromExp(int experience) {
|
||||
final exp = kExperienceToLevelRequirements.reversed.firstWhere((x) => x <= experience);
|
||||
final idx = kExperienceToLevelRequirements.indexOf(exp);
|
||||
return idx;
|
||||
}
|
||||
|
||||
double calcLevelUpProgress(int experience) {
|
||||
final exp = kExperienceToLevelRequirements.reversed.firstWhere((x) => x <= experience);
|
||||
final idx = kExperienceToLevelRequirements.indexOf(exp);
|
||||
if (idx + 1 >= kExperienceToLevelRequirements.length) return 1;
|
||||
final nextExp = kExperienceToLevelRequirements[idx + 1];
|
||||
return (experience - exp).abs() / (exp - nextExp).abs();
|
||||
}
|
||||
|
||||
String calcLevelUpProgressLevel(int experience) {
|
||||
final exp = kExperienceToLevelRequirements.reversed.firstWhere((x) => x <= experience);
|
||||
final idx = kExperienceToLevelRequirements.indexOf(exp);
|
||||
if (idx + 1 >= kExperienceToLevelRequirements.length) return 'Infinity';
|
||||
final nextExp = exp - kExperienceToLevelRequirements[idx + 1];
|
||||
final formatter = NumberFormat.compactCurrency(symbol: '', decimalDigits: 1);
|
||||
return '${formatter.format((exp - experience).abs())}/${formatter.format(nextExp.abs())}';
|
||||
}
|
@ -77,11 +77,8 @@ final _appRoutes = [
|
||||
GoRoute(
|
||||
path: '/search',
|
||||
name: 'postSearch',
|
||||
builder: (context, state) => AppBackground(
|
||||
child: PostSearchScreen(
|
||||
initialTags: state.uri.queryParameters['tags']?.split(','),
|
||||
initialCategories: state.uri.queryParameters['categories']?.split(','),
|
||||
),
|
||||
builder: (context, state) => const AppBackground(
|
||||
child: PostSearchScreen(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@ -10,12 +9,10 @@ import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:relative_time/relative_time.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:surface/providers/experience.dart';
|
||||
import 'package:surface/providers/relationship.dart';
|
||||
import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/screens/abuse_report.dart';
|
||||
import 'package:surface/types/account.dart';
|
||||
import 'package:surface/types/check_in.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
@ -64,19 +61,6 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<SnCheckInRecord>> _getCheckInRecords() async {
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
final resp = await sn.client.get('/cgi/id/users/${widget.name}/check-in?take=14');
|
||||
return List.from(
|
||||
resp.data['data']?.map((x) => SnCheckInRecord.fromJson(x)) ?? [],
|
||||
);
|
||||
} catch (err) {
|
||||
if (mounted) context.showErrorDialog(err);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
SnAccountStatusInfo? _status;
|
||||
|
||||
Future<void> _fetchStatus() async {
|
||||
@ -453,7 +437,6 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
|
||||
Column(
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Symbols.calendar_add_on),
|
||||
const Gap(8),
|
||||
@ -461,7 +444,6 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
|
||||
],
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Symbols.cake),
|
||||
const Gap(8),
|
||||
@ -475,7 +457,6 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
|
||||
],
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Symbols.identity_platform),
|
||||
const Gap(8),
|
||||
@ -485,26 +466,6 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
|
||||
).opacity(0.8),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Symbols.star),
|
||||
const Gap(8),
|
||||
Text('Lv${getLevelFromExp(_account?.profile?.experience ?? 0)}'),
|
||||
const Gap(8),
|
||||
Text(calcLevelUpProgressLevel(_account?.profile?.experience ?? 0)).fontSize(11).opacity(0.5),
|
||||
const Gap(8),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
constraints: const BoxConstraints(maxWidth: 160),
|
||||
child: LinearProgressIndicator(
|
||||
value: calcLevelUpProgress(_account?.profile?.experience ?? 0),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||
).alignment(Alignment.centerLeft),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
).padding(horizontal: 8),
|
||||
],
|
||||
@ -512,27 +473,6 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
|
||||
),
|
||||
SliverToBoxAdapter(child: const Divider()),
|
||||
const SliverGap(12),
|
||||
SliverToBoxAdapter(
|
||||
child: FutureBuilder<List<SnCheckInRecord>>(
|
||||
future: _getCheckInRecords(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) return const SizedBox.shrink();
|
||||
final records = snapshot.data!;
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 240,
|
||||
child: CheckInRecordChart(records: records),
|
||||
).padding(
|
||||
right: 24,
|
||||
left: 16,
|
||||
top: 12,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SliverGap(12),
|
||||
SliverToBoxAdapter(child: const Divider()),
|
||||
const SliverGap(12),
|
||||
SliverToBoxAdapter(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -601,105 +541,3 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CheckInRecordChart extends StatelessWidget {
|
||||
const CheckInRecordChart({
|
||||
super.key,
|
||||
required this.records,
|
||||
});
|
||||
|
||||
final List<SnCheckInRecord> records;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LineChart(
|
||||
LineChartData(
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
gradient: LinearGradient(
|
||||
colors: List.filled(
|
||||
records.length,
|
||||
Theme.of(context).colorScheme.primary.withOpacity(0.3),
|
||||
).toList(),
|
||||
),
|
||||
),
|
||||
spots: records
|
||||
.map(
|
||||
(x) => FlSpot(
|
||||
x.createdAt
|
||||
.copyWith(
|
||||
hour: 0,
|
||||
minute: 0,
|
||||
second: 0,
|
||||
millisecond: 0,
|
||||
microsecond: 0,
|
||||
)
|
||||
.millisecondsSinceEpoch
|
||||
.toDouble(),
|
||||
x.resultTier.toDouble(),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
)
|
||||
],
|
||||
lineTouchData: LineTouchData(
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
getTooltipItems: (spots) => spots
|
||||
.map(
|
||||
(spot) => LineTooltipItem(
|
||||
'${kCheckInResultTierSymbols[spot.y.toInt()]}\n${DateFormat('MM/dd').format(DateTime.fromMillisecondsSinceEpoch(spot.x.toInt()))}',
|
||||
TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
getTooltipColor: (_) => Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
),
|
||||
),
|
||||
titlesData: FlTitlesData(
|
||||
topTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
rightTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
leftTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 40,
|
||||
interval: 1,
|
||||
getTitlesWidget: (value, _) => Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
kCheckInResultTierSymbols[value.toInt()],
|
||||
textAlign: TextAlign.right,
|
||||
).padding(right: 8),
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 28,
|
||||
interval: 86400000,
|
||||
getTitlesWidget: (value, _) => Text(
|
||||
DateFormat('dd').format(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
value.toInt(),
|
||||
),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
).padding(top: 8),
|
||||
),
|
||||
),
|
||||
),
|
||||
gridData: const FlGridData(show: false),
|
||||
borderData: FlBorderData(show: false),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -181,11 +181,11 @@ class _ExploreScreenState extends State<ExploreScreen> {
|
||||
const Gap(8),
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(50),
|
||||
preferredSize: const Size.fromHeight(40),
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
height: 40,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 12),
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: _categories.length,
|
||||
itemBuilder: (context, idx) {
|
||||
|
@ -13,10 +13,7 @@ import 'package:surface/widgets/post/post_tags_field.dart';
|
||||
import 'package:very_good_infinite_list/very_good_infinite_list.dart';
|
||||
|
||||
class PostSearchScreen extends StatefulWidget {
|
||||
final Iterable<String>? initialTags;
|
||||
final Iterable<String>? initialCategories;
|
||||
|
||||
const PostSearchScreen({super.key, this.initialTags, this.initialCategories});
|
||||
const PostSearchScreen({super.key});
|
||||
|
||||
@override
|
||||
State<PostSearchScreen> createState() => _PostSearchScreenState();
|
||||
@ -34,16 +31,6 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
|
||||
String _searchTerm = '';
|
||||
Duration? _lastTook;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_searchTags.addAll(widget.initialTags ?? []);
|
||||
_searchCategories.addAll(widget.initialCategories ?? []);
|
||||
if (_searchTags.isNotEmpty || _searchCategories.isNotEmpty) {
|
||||
_fetchPosts();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchPosts() async {
|
||||
if (_searchTerm.isEmpty && _searchCategories.isEmpty && _searchTags.isEmpty) return;
|
||||
if (_postCount != null && _posts.length >= _postCount!) return;
|
||||
|
@ -45,9 +45,17 @@ class _PostPublisherScreenState extends State<PostPublisherScreen> with SingleTi
|
||||
Future<void> _fetchPublisher() async {
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
final ud = context.read<UserDirectoryProvider>();
|
||||
final rel = context.read<SnRelationshipProvider>();
|
||||
final resp = await sn.client.get('/cgi/co/publishers/${widget.name}');
|
||||
if (!mounted) return;
|
||||
_publisher = SnPublisher.fromJson(resp.data);
|
||||
_account = await ud.getAccount(_publisher?.accountId);
|
||||
_accountRelationship = await rel.getRelationship(_account!.id);
|
||||
if (_publisher?.realmId != null && _publisher!.realmId != 0) {
|
||||
final resp = await sn.client.get('/cgi/id/realms/${_publisher!.realmId}');
|
||||
_realm = SnRealm.fromJson(resp.data);
|
||||
}
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err).then((_) {
|
||||
@ -57,20 +65,6 @@ class _PostPublisherScreenState extends State<PostPublisherScreen> with SingleTi
|
||||
} finally {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
final ud = context.read<UserDirectoryProvider>();
|
||||
final rel = context.read<SnRelationshipProvider>();
|
||||
_account = await ud.getAccount(_publisher?.accountId);
|
||||
_accountRelationship = await rel.getRelationship(_account!.id);
|
||||
if (_publisher?.realmId != null && _publisher!.realmId != 0) {
|
||||
final resp = await sn.client.get('/cgi/id/realms/${_publisher!.realmId}');
|
||||
_realm = SnRealm.fromJson(resp.data);
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
bool _isSubscribing = false;
|
||||
|
@ -3,8 +3,6 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
part 'check_in.freezed.dart';
|
||||
part 'check_in.g.dart';
|
||||
|
||||
const List<String> kCheckInResultTierSymbols = ['大凶', '凶', '中平', '吉', '大吉'];
|
||||
|
||||
@freezed
|
||||
class SnCheckInRecord with _$SnCheckInRecord {
|
||||
const SnCheckInRecord._();
|
||||
@ -23,5 +21,11 @@ class SnCheckInRecord with _$SnCheckInRecord {
|
||||
factory SnCheckInRecord.fromJson(Map<String, dynamic> json) =>
|
||||
_$SnCheckInRecordFromJson(json);
|
||||
|
||||
String get symbol => kCheckInResultTierSymbols[resultTier];
|
||||
String get symbol => switch (resultTier) {
|
||||
0 => '大凶',
|
||||
1 => '凶',
|
||||
2 => '中平',
|
||||
3 => '吉',
|
||||
_ => '大吉',
|
||||
};
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class ChatMessage extends StatelessWidget {
|
||||
onEdit: onEdit,
|
||||
onDelete: onDelete,
|
||||
),
|
||||
)).padding(bottom: 4, top: 4),
|
||||
)).padding(bottom: 4, top: isMerged ? 4 : 2),
|
||||
switch (data.type) {
|
||||
'messages.new' => _ChatMessageText(data: data),
|
||||
_ => _ChatMessageSystemNotify(data: data),
|
||||
|
@ -989,14 +989,7 @@ class _PostTagsList extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed(
|
||||
'postSearch',
|
||||
queryParameters: {
|
||||
'categories': ele.alias,
|
||||
},
|
||||
);
|
||||
},
|
||||
onTap: () {},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
@ -1015,14 +1008,7 @@ class _PostTagsList extends StatelessWidget {
|
||||
Text(ele.alias, style: GoogleFonts.robotoMono()),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed(
|
||||
'postSearch',
|
||||
queryParameters: {
|
||||
'tags': ele.alias,
|
||||
},
|
||||
);
|
||||
},
|
||||
onTap: () {},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
|
10
pubspec.lock
10
pubspec.lock
@ -614,14 +614,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
fl_chart:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: fl_chart
|
||||
sha256: c724234b05e378383e958f3e82ca84a3e1e3c06a0898462044dd8a24b1ee9864
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.70.0"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@ -2153,4 +2145,4 @@ packages:
|
||||
version: "3.1.3"
|
||||
sdks:
|
||||
dart: ">=3.6.0 <4.0.0"
|
||||
flutter: ">=3.27.0"
|
||||
flutter: ">=3.24.0"
|
||||
|
@ -112,7 +112,6 @@ dependencies:
|
||||
in_app_review: ^2.0.10
|
||||
version: ^3.0.2
|
||||
flutter_colorpicker: ^1.1.0
|
||||
fl_chart: ^0.70.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
Reference in New Issue
Block a user