opt: get theme color

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-28 21:32:30 +08:00
parent 451a84e696
commit ca993df0c6
149 changed files with 4415 additions and 4803 deletions

View File

@@ -47,9 +47,10 @@ class _EditProfilePageState extends State<EditProfilePage> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text('账号资料')),
body: _buildBody(_loadingState),
body: _buildBody(theme, _loadingState),
);
}
@@ -77,23 +78,24 @@ class _EditProfilePageState extends State<EditProfilePage> {
});
}
Widget get _divider => Divider(
height: 1,
color: Theme.of(context).dividerColor.withOpacity(0.1),
);
Widget _buildBody(ThemeData theme, LoadingState loadingState) {
late final divider = Divider(
height: 1,
color: theme.dividerColor.withOpacity(0.1),
);
Widget get _divider1 => Divider(
thickness: 16,
color: Theme.of(context).dividerColor.withOpacity(0.1),
);
late final divider1 = Divider(
thickness: 16,
color: theme.dividerColor.withOpacity(0.1),
);
Widget _buildBody(LoadingState loadingState) {
return switch (loadingState) {
Loading() => loadingWidget,
Success() => SingleChildScrollView(
child: Column(
children: [
_item(
theme: theme,
title: '头像',
widget: Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
@@ -108,12 +110,13 @@ class _EditProfilePageState extends State<EditProfilePage> {
EasyThrottle.throttle(
'imagePicker', const Duration(milliseconds: 500),
() async {
_pickImg();
_pickImg(theme);
});
},
),
_divider,
divider,
_item(
theme: theme,
title: '昵称',
text: loadingState.response['name'],
onTap: () {
@@ -128,8 +131,9 @@ class _EditProfilePageState extends State<EditProfilePage> {
}
},
),
_divider,
divider,
_item(
theme: theme,
title: '性别',
text: _sex(loadingState.response['sex']),
onTap: () {
@@ -140,8 +144,9 @@ class _EditProfilePageState extends State<EditProfilePage> {
);
},
),
_divider,
divider,
_item(
theme: theme,
title: '出生年月',
text: loadingState.response['birthday'],
onTap: () {
@@ -161,8 +166,9 @@ class _EditProfilePageState extends State<EditProfilePage> {
});
},
),
_divider,
divider,
_item(
theme: theme,
title: '个性签名',
text: loadingState.response['sign'].isEmpty
? ''
@@ -175,27 +181,30 @@ class _EditProfilePageState extends State<EditProfilePage> {
);
},
),
_divider1,
divider1,
_item(
theme: theme,
title: '头像挂件',
onTap: () => PageUtils.launchURL(
'https://www.bilibili.com/h5/mall/pendant/home'),
),
_divider1,
divider1,
_item(
theme: theme,
title: 'UID',
needIcon: false,
text: loadingState.response['mid'].toString(),
onTap: () =>
Utils.copyText(loadingState.response['mid'].toString()),
),
_divider1,
divider1,
_item(
theme: theme,
title: '哔哩哔哩认证',
onTap: () => PageUtils.launchURL(
'https://account.bilibili.com/official/mobile/home'),
),
_divider,
divider,
SizedBox(height: 25 + MediaQuery.paddingOf(context).bottom),
],
),
@@ -254,6 +263,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
showDialog(
context: context,
builder: (BuildContext context) {
final theme = Theme.of(context);
return AlertDialog(
title: Text('修改$title'),
content: TextField(
@@ -272,7 +282,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
hintText: text,
hintStyle: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.outline,
color: theme.colorScheme.outline,
),
),
),
@@ -281,7 +291,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
onPressed: Get.back,
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
style: TextStyle(color: theme.colorScheme.outline),
),
),
TextButton(
@@ -372,6 +382,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
}
Widget _item({
required ThemeData theme,
required String title,
Widget? widget,
String? text,
@@ -399,7 +410,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal,
color: Theme.of(context).colorScheme.outline,
color: theme.colorScheme.outline,
),
)
else if (widget != null)
@@ -407,14 +418,14 @@ class _EditProfilePageState extends State<EditProfilePage> {
if (needIcon)
Icon(
Icons.keyboard_arrow_right,
color: Theme.of(context).colorScheme.outline,
color: theme.colorScheme.outline,
)
],
),
);
}
void _pickImg() async {
void _pickImg(ThemeData theme) async {
try {
XFile? pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
@@ -432,9 +443,8 @@ class _EditProfilePageState extends State<EditProfilePage> {
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
toolbarColor: Theme.of(context).colorScheme.secondaryContainer,
toolbarWidgetColor:
Theme.of(context).colorScheme.onSecondaryContainer,
toolbarColor: theme.colorScheme.secondaryContainer,
toolbarWidgetColor: theme.colorScheme.onSecondaryContainer,
aspectRatioPresets: [
CropAspectRatioPresetCustom(),
],

View File

@@ -38,10 +38,12 @@ class UserInfoCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return isV ? _buildV(context) : _buildH(context);
final theme = Theme.of(context);
return isV ? _buildV(context, theme) : _buildH(context, theme);
}
Widget _countWidget({
required ThemeData theme,
required String title,
required int count,
required VoidCallback onTap,
@@ -62,7 +64,7 @@ class UserInfoCard extends StatelessWidget {
style: TextStyle(
height: 1,
fontSize: 11,
color: Theme.of(Get.context!).colorScheme.outline,
color: theme.colorScheme.outline,
),
),
],
@@ -70,8 +72,8 @@ class UserInfoCard extends StatelessWidget {
);
}
_buildHeader(BuildContext context) {
bool darken = Theme.of(context).brightness == Brightness.dark;
_buildHeader(BuildContext context, ThemeData theme) {
bool darken = theme.brightness == Brightness.dark;
String imgUrl = (darken
? images.nightImgurl?.isEmpty == true
? images.imgUrl
@@ -107,7 +109,7 @@ class UserInfoCard extends StatelessWidget {
);
}
_buildLeft(BuildContext context) => [
_buildLeft(BuildContext context, ThemeData theme) => [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Wrap(
@@ -181,7 +183,7 @@ class UserInfoCard extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(12)),
color: Theme.of(context).colorScheme.onInverseSurface,
color: theme.colorScheme.onInverseSurface,
),
child: Text.rich(
TextSpan(
@@ -192,7 +194,7 @@ class UserInfoCard extends StatelessWidget {
child: DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.surface,
color: theme.colorScheme.surface,
),
child: Icon(
Icons.offline_bolt,
@@ -212,10 +214,7 @@ class UserInfoCard extends StatelessWidget {
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.7),
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
)
],
@@ -245,7 +244,7 @@ class UserInfoCard extends StatelessWidget {
'UID: ${card.mid}',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
color: theme.colorScheme.outline,
),
),
),
@@ -255,7 +254,7 @@ class UserInfoCard extends StatelessWidget {
item.title ?? '',
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.outline,
color: theme.colorScheme.outline,
),
),
),
@@ -264,14 +263,14 @@ class UserInfoCard extends StatelessWidget {
),
if (silence == 1)
Builder(builder: (context) {
bool isLight = Theme.of(context).brightness == Brightness.light;
bool isLight = theme.brightness == Brightness.light;
return Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: isLight
? Theme.of(context).colorScheme.errorContainer
: Theme.of(context).colorScheme.error,
? theme.colorScheme.errorContainer
: theme.colorScheme.error,
),
margin: const EdgeInsets.only(left: 20, top: 8, right: 20),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
@@ -284,16 +283,16 @@ class UserInfoCard extends StatelessWidget {
Icons.info,
size: 17,
color: isLight
? Theme.of(context).colorScheme.onErrorContainer
: Theme.of(context).colorScheme.onError,
? theme.colorScheme.onErrorContainer
: theme.colorScheme.onError,
),
),
TextSpan(
text: ' 该账号封禁中${endTime ?? ''}',
style: TextStyle(
color: isLight
? Theme.of(context).colorScheme.onErrorContainer
: Theme.of(context).colorScheme.onError,
? theme.colorScheme.onErrorContainer
: theme.colorScheme.onError,
),
),
],
@@ -303,7 +302,7 @@ class UserInfoCard extends StatelessWidget {
}),
];
_buildRight(BuildContext context) => Column(
_buildRight(BuildContext context, ThemeData theme) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
@@ -312,6 +311,7 @@ class UserInfoCard extends StatelessWidget {
5,
(index) => index % 2 == 0
? _countWidget(
theme: theme,
title: ['粉丝', '关注', '获赞'][index ~/ 2],
count: index == 0
? card.fans
@@ -358,10 +358,7 @@ class UserInfoCard extends StatelessWidget {
style: IconButton.styleFrom(
side: BorderSide(
width: 1.0,
color: Theme.of(context)
.colorScheme
.outline
.withOpacity(0.5),
color: theme.colorScheme.outline.withOpacity(0.5),
),
padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
@@ -378,7 +375,7 @@ class UserInfoCard extends StatelessWidget {
onPressed: onFollow,
style: FilledButton.styleFrom(
backgroundColor: relation != 0
? Theme.of(context).colorScheme.onInverseSurface
? theme.colorScheme.onInverseSurface
: null,
visualDensity: const VisualDensity(
horizontal: -2,
@@ -387,9 +384,7 @@ class UserInfoCard extends StatelessWidget {
),
child: Text.rich(
style: TextStyle(
color: relation != 0
? Theme.of(context).colorScheme.outline
: null,
color: relation != 0 ? theme.colorScheme.outline : null,
),
TextSpan(
children: [
@@ -399,7 +394,7 @@ class UserInfoCard extends StatelessWidget {
child: Icon(
Icons.sort,
size: 16,
color: Theme.of(context).colorScheme.outline,
color: theme.colorScheme.outline,
),
),
TextSpan(
@@ -440,7 +435,7 @@ class UserInfoCard extends StatelessWidget {
.imageView(imgList: [SourceModel(url: card.face.http2https)]),
));
_buildV(BuildContext context) => Column(
_buildV(BuildContext context, ThemeData theme) => Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -450,7 +445,7 @@ class UserInfoCard extends StatelessWidget {
Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildHeader(context),
_buildHeader(context, theme),
const SizedBox(width: double.infinity, height: 85)
],
),
@@ -468,21 +463,21 @@ class UserInfoCard extends StatelessWidget {
builder: (_, constraints) => FittedBox(
child: SizedBox(
width: constraints.maxWidth,
child: _buildRight(context),
child: _buildRight(context, theme),
),
),
),
),
],
),
..._buildLeft(context),
if (card.prInfo?.content?.isNotEmpty == true) buildPrInfo,
..._buildLeft(context, theme),
if (card.prInfo?.content?.isNotEmpty == true) buildPrInfo(theme),
const SizedBox(height: 5),
],
);
Widget get buildPrInfo => Builder(builder: (context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
Widget buildPrInfo(ThemeData theme) => Builder(builder: (context) {
final isDark = theme.brightness == Brightness.dark;
final textColor = isDark
? Color(int.parse('FF${card.prInfo?.textColorNight?.substring(1)}',
radix: 16))
@@ -537,7 +532,7 @@ class UserInfoCard extends StatelessWidget {
);
});
_buildH(BuildContext context) => Column(
_buildH(BuildContext context, ThemeData theme) => Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -565,16 +560,16 @@ class UserInfoCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
..._buildLeft(context),
..._buildLeft(context, theme),
const SizedBox(height: 5),
],
),
),
Expanded(child: _buildRight(context)),
Expanded(child: _buildRight(context, theme)),
],
),
),
if (card.prInfo?.content?.isNotEmpty == true) buildPrInfo,
if (card.prInfo?.content?.isNotEmpty == true) buildPrInfo(theme),
],
);
}