pikapika/lib/screens/components/UserProfileCard.dart

160 lines
4.8 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
import 'dart:ui';
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/Common.dart';
import 'package:pikapika/basic/Entities.dart';
2022-02-24 16:08:18 +00:00
import 'package:pikapika/basic/Method.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/screens/components/Avatar.dart';
import 'package:pikapika/screens/components/Images.dart';
2022-02-24 16:08:18 +00:00
import 'package:pikapika/screens/components/ItemBuilder.dart';
const double _cardHeight = 180;
2021-09-29 23:57:09 +00:00
// 用户信息卡
class UserProfileCard extends StatefulWidget {
@override
State<StatefulWidget> createState() => _UserProfileCardState();
}
class _UserProfileCardState extends State<UserProfileCard> {
late Future<UserProfile> _future = _load();
Future<UserProfile> _load() async {
var profile = await method.userProfile();
if (!profile.isPunched) {
await method.punchIn();
profile.isPunched = true;
defaultToast(context, "自动打卡");
}
return profile;
}
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
2022-02-24 16:08:18 +00:00
var nameStyle = TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
);
var nameStrutStyle = StrutStyle(
fontSize: 14,
forceStrutHeight: true,
fontWeight: FontWeight.bold,
);
2021-09-29 23:57:09 +00:00
var levelStyle = TextStyle(
2022-02-24 16:08:18 +00:00
fontSize: 12,
color: theme.colorScheme.secondary.withOpacity(.9),
fontWeight: FontWeight.bold,
);
var levelStrutStyle = StrutStyle(
fontSize: 12,
forceStrutHeight: true,
fontWeight: FontWeight.bold,
);
var sloganStyle = TextStyle(
fontSize: 10,
color: theme.textTheme.bodyText1?.color?.withOpacity(.5),
);
var sloganStrutStyle = StrutStyle(
fontSize: 10,
forceStrutHeight: true,
);
2021-09-29 23:57:09 +00:00
return ItemBuilder(
future: _future,
onRefresh: () async {
setState(() => _future = method.userProfile());
},
2022-02-24 16:08:18 +00:00
height: _cardHeight,
2021-09-29 23:57:09 +00:00
successBuilder:
(BuildContext context, AsyncSnapshot<UserProfile> snapshot) {
UserProfile profile = snapshot.data!;
return Stack(
children: [
Container(
child: Stack(
children: [
Opacity(
opacity: .25, //
child: LayoutBuilder(
builder:
(BuildContext context, BoxConstraints constraints) {
return RemoteImage(
path: profile.avatar.path,
fileServer: profile.avatar.fileServer,
width: constraints.maxWidth,
2022-02-24 16:08:18 +00:00
height: _cardHeight,
2021-09-29 23:57:09 +00:00
);
},
),
),
Positioned.fromRect(
rect: Rect.largest,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 30, sigmaY: 30),
child: Container(),
),
),
],
),
),
Container(
2022-02-24 16:08:18 +00:00
height: _cardHeight,
2021-09-29 23:57:09 +00:00
child: Column(
children: [
Expanded(child: Container()),
2022-02-24 16:08:18 +00:00
Avatar(profile.avatar, size: 65),
Container(height: 5),
2021-09-29 23:57:09 +00:00
Text(
profile.name,
style: nameStyle,
2022-02-24 16:08:18 +00:00
strutStyle: nameStrutStyle,
2021-09-29 23:57:09 +00:00
),
Text(
"Lv. ${profile.level} (${profile.title})",
style: levelStyle,
2022-02-24 16:08:18 +00:00
strutStyle: levelStrutStyle,
),
Container(height: 8),
GestureDetector(
onTap: () async {
var input = await inputString(
context,
"更新签名",
defaultValue: profile.slogan ?? "",
);
if (input != null) {
await method.updateSlogan(input);
setState(() {
_future = _load();
});
}
},
child: Text(
profile.slogan == null || profile.slogan!.isEmpty
? "这个人很懒, 什么也没留下"
: profile.slogan!,
style: sloganStyle,
strutStyle: sloganStrutStyle,
),
2021-09-29 23:57:09 +00:00
),
Expanded(child: Container()),
],
),
)
],
);
},
);
}
}