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

@@ -24,6 +24,7 @@ class _AtMePageState extends State<AtMePage> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('@我的'),
@@ -38,7 +39,8 @@ class _AtMePageState extends State<AtMePage> {
SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80),
sliver: Obx(() => _buildBody(_atMeController.loadingState.value)),
sliver: Obx(
() => _buildBody(theme, _atMeController.loadingState.value)),
),
],
),
@@ -46,7 +48,8 @@ class _AtMePageState extends State<AtMePage> {
);
}
Widget _buildBody(LoadingState<List<AtMeItems>?> loadingState) {
Widget _buildBody(
ThemeData theme, LoadingState<List<AtMeItems>?> loadingState) {
return switch (loadingState) {
Loading() => SliverList.builder(
itemCount: 12,
@@ -94,21 +97,15 @@ class _AtMePageState extends State<AtMePage> {
children: [
TextSpan(
text: "${item.user?.nickname}",
style: Theme.of(context)
.textTheme
.titleSmall!
.copyWith(
color: Theme.of(context).colorScheme.primary,
),
style: theme.textTheme.titleSmall!.copyWith(
color: theme.colorScheme.primary,
),
),
TextSpan(
text: "${item.item?.business}中@了我",
style:
Theme.of(context).textTheme.titleSmall!.copyWith(
color: Theme.of(context)
.colorScheme
.onSurfaceVariant,
),
style: theme.textTheme.titleSmall!.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
@@ -121,20 +118,16 @@ class _AtMePageState extends State<AtMePage> {
Text(item.item!.sourceContent!,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline)),
style: theme.textTheme.bodyMedium!
.copyWith(color: theme.colorScheme.outline)),
],
const SizedBox(height: 4),
Text(
Utils.dateFormat(item.atTime),
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontSize: 13,
color: Theme.of(context).colorScheme.outline,
),
style: theme.textTheme.bodyMedium!.copyWith(
fontSize: 13,
color: theme.colorScheme.outline,
),
),
],
),

View File

@@ -57,6 +57,7 @@ class _LikeMePageState extends State<LikeMePage> {
},
),
Success() => () {
final theme = Theme.of(context);
Pair<List<LikeMeItems>, List<LikeMeItems>> pair =
loadingState.response;
List<LikeMeItems> latest = pair.first;
@@ -65,13 +66,14 @@ class _LikeMePageState extends State<LikeMePage> {
return SliverMainAxisGroup(
slivers: [
if (latest.isNotEmpty) ...[
_buildHeader('最新'),
_buildHeader(theme, '最新'),
SliverList.separated(
itemBuilder: (context, index) {
if (total.isEmpty && index == latest.length - 1) {
_likeMeController.onLoadMore();
}
return _buildItem(
theme,
latest[index],
(id) {
_likeMeController.onRemove(id, index, true);
@@ -90,13 +92,14 @@ class _LikeMePageState extends State<LikeMePage> {
),
],
if (total.isNotEmpty) ...[
_buildHeader('累计'),
_buildHeader(theme, '累计'),
SliverList.separated(
itemBuilder: (context, index) {
if (index == total.length - 1) {
_likeMeController.onLoadMore();
}
return _buildItem(
theme,
total[index],
(id) {
_likeMeController.onRemove(id, index, false);
@@ -126,7 +129,7 @@ class _LikeMePageState extends State<LikeMePage> {
};
}
Widget _buildHeader(String title) {
Widget _buildHeader(ThemeData theme, String title) {
return SliverSafeArea(
top: false,
bottom: false,
@@ -135,16 +138,16 @@ class _LikeMePageState extends State<LikeMePage> {
padding: const EdgeInsets.only(left: 16),
child: Text(
title,
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: Theme.of(context).colorScheme.secondary,
),
style: theme.textTheme.labelLarge!.copyWith(
color: theme.colorScheme.secondary,
),
),
),
),
);
}
Widget _buildItem(LikeMeItems item, ValueChanged onRemove) {
Widget _buildItem(ThemeData theme, LikeMeItems item, ValueChanged onRemove) {
return ListTile(
onTap: () {
String? nativeUri = item.item?.nativeUri;
@@ -193,23 +196,21 @@ class _LikeMePageState extends State<LikeMePage> {
children: [
TextSpan(
text: "${item.users![0].nickname}",
style: Theme.of(context).textTheme.titleSmall!.copyWith(
height: 1.5, color: Theme.of(context).colorScheme.primary),
style: theme.textTheme.titleSmall!
.copyWith(height: 1.5, color: theme.colorScheme.primary),
),
if (item.counts! > 1)
TextSpan(
text: '${item.counts}',
style: Theme.of(context)
.textTheme
.titleSmall!
style: theme.textTheme.titleSmall!
.copyWith(fontSize: 12, height: 1.5),
),
TextSpan(
text: " 赞了我的${item.item?.business}",
style: Theme.of(context).textTheme.titleSmall!.copyWith(
height: 1.5,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
style: theme.textTheme.titleSmall!.copyWith(
height: 1.5,
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
@@ -224,16 +225,16 @@ class _LikeMePageState extends State<LikeMePage> {
Text(item.item!.title!,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.outline, height: 1.5)),
style: theme.textTheme.bodyMedium!
.copyWith(color: theme.colorScheme.outline, height: 1.5)),
],
const SizedBox(height: 4),
Text(
Utils.dateFormat(item.likeTime),
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontSize: 13,
color: Theme.of(context).colorScheme.outline,
),
style: theme.textTheme.bodyMedium!.copyWith(
fontSize: 13,
color: theme.colorScheme.outline,
),
),
],
),

View File

@@ -24,6 +24,7 @@ class _ReplyMePageState extends State<ReplyMePage> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text('回复我的')),
body: refreshIndicator(
@@ -36,8 +37,8 @@ class _ReplyMePageState extends State<ReplyMePage> {
SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80),
sliver:
Obx(() => _buildBody(_replyMeController.loadingState.value)),
sliver: Obx(() =>
_buildBody(theme, _replyMeController.loadingState.value)),
),
],
),
@@ -45,7 +46,8 @@ class _ReplyMePageState extends State<ReplyMePage> {
);
}
Widget _buildBody(LoadingState<List<ReplyMeItems>?> loadingState) {
Widget _buildBody(
ThemeData theme, LoadingState<List<ReplyMeItems>?> loadingState) {
return switch (loadingState) {
Loading() => SliverList.builder(
itemCount: 12,
@@ -98,30 +100,20 @@ class _ReplyMePageState extends State<ReplyMePage> {
children: [
TextSpan(
text: "${item.user?.nickname}",
style: Theme.of(context)
.textTheme
.titleSmall!
.copyWith(
color: Theme.of(context).colorScheme.primary),
style: theme.textTheme.titleSmall!
.copyWith(color: theme.colorScheme.primary),
),
if (item.isMulti == 1)
TextSpan(
text: " 等人",
style: Theme.of(context)
.textTheme
.titleSmall!
style: theme.textTheme.titleSmall!
.copyWith(fontSize: 12),
),
TextSpan(
text:
" 对我的${item.item?.business}发布了${item.counts}条评论",
style: Theme.of(context)
.textTheme
.titleSmall!
.copyWith(
color: Theme.of(context)
.colorScheme
.onSurfaceVariant),
style: theme.textTheme.titleSmall!.copyWith(
color: theme.colorScheme.onSurfaceVariant),
),
],
),
@@ -132,38 +124,28 @@ class _ReplyMePageState extends State<ReplyMePage> {
children: [
const SizedBox(height: 4),
Text(item.item?.sourceContent ?? "",
style: Theme.of(context).textTheme.bodyMedium),
style: theme.textTheme.bodyMedium),
const SizedBox(height: 4),
if (item.item?.targetReplyContent != null &&
item.item?.targetReplyContent != "")
Text("| ${item.item?.targetReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline,
height: 1.5)),
style: theme.textTheme.labelMedium!.copyWith(
color: theme.colorScheme.outline, height: 1.5)),
if (item.item?.rootReplyContent != null &&
item.item?.rootReplyContent != "")
Text(" | ${item.item?.rootReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline,
height: 1.5)),
style: theme.textTheme.labelMedium!.copyWith(
color: theme.colorScheme.outline, height: 1.5)),
Text(
Utils.dateFormat(item.replyTime),
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
fontSize: 13,
color: Theme.of(context).colorScheme.outline,
),
style: theme.textTheme.bodyMedium!.copyWith(
fontSize: 13,
color: theme.colorScheme.outline,
),
),
],
),

View File

@@ -29,6 +29,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('系统通知'),
@@ -43,8 +44,8 @@ class _SysMsgPageState extends State<SysMsgPage> {
SliverPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 80),
sliver:
Obx(() => _buildBody(_sysMsgController.loadingState.value)),
sliver: Obx(() =>
_buildBody(theme, _sysMsgController.loadingState.value)),
),
],
),
@@ -52,7 +53,8 @@ class _SysMsgPageState extends State<SysMsgPage> {
);
}
Widget _buildBody(LoadingState<List<SystemNotifyList>?> loadingState) {
Widget _buildBody(
ThemeData theme, LoadingState<List<SystemNotifyList>?> loadingState) {
return switch (loadingState) {
Loading() => SliverSafeArea(
sliver: SliverList.builder(
@@ -92,20 +94,17 @@ class _SysMsgPageState extends State<SysMsgPage> {
},
title: Text(
"${item.title}",
style: Theme.of(context).textTheme.titleMedium,
style: theme.textTheme.titleMedium,
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text.rich(
_buildContent(content ?? ''),
_buildContent(theme, content ?? ''),
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.85),
color: theme.colorScheme.onSurface.withOpacity(0.85),
),
),
const SizedBox(height: 5),
@@ -115,13 +114,10 @@ class _SysMsgPageState extends State<SysMsgPage> {
"${item.timeAt}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(
fontSize: 13,
color: Theme.of(context).colorScheme.outline,
),
style: theme.textTheme.bodyMedium!.copyWith(
fontSize: 13,
color: theme.colorScheme.outline,
),
textAlign: TextAlign.end,
),
),
@@ -146,7 +142,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
};
}
InlineSpan _buildContent(String content) {
InlineSpan _buildContent(ThemeData theme, String content) {
final List<InlineSpan> spanChildren = <InlineSpan>[];
RegExp urlRegExp = RegExp(
r'#\{([^}]*)\}\{([^}]*)\}|https?:\/\/[^\s/\$.?#].[^\s]*|www\.[^\s/\$.?#].[^\s]*|【(.*?)】|(\d+)');
@@ -158,7 +154,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
spanChildren.add(
TextSpan(
text: match[1],
style: TextStyle(color: Theme.of(context).colorScheme.primary),
style: TextStyle(color: theme.colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () {
try {
@@ -181,7 +177,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
spanChildren.add(
TextSpan(
text: match[3],
style: TextStyle(color: Theme.of(context).colorScheme.primary),
style: TextStyle(color: theme.colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () {
try {
@@ -206,7 +202,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
spanChildren.add(
TextSpan(
text: '查看动态',
style: TextStyle(color: Theme.of(context).colorScheme.primary),
style: TextStyle(color: theme.colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () {
try {
@@ -225,7 +221,7 @@ class _SysMsgPageState extends State<SysMsgPage> {
spanChildren.add(
TextSpan(
text: '\u{1F517}网页链接',
style: TextStyle(color: Theme.of(context).colorScheme.primary),
style: TextStyle(color: theme.colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () {
try {