Skip to content

Commit

Permalink
fix: disable text shadow for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Dec 16, 2024
1 parent 9c5d5a5 commit e558e7d
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 29 deletions.
64 changes: 49 additions & 15 deletions lib/view/dialog/image_gallery_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:gal/gal.dart';
Expand Down Expand Up @@ -207,23 +208,10 @@ class ImageGalleryDialog extends HookConsumerWidget {
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 100.0),
child: SingleChildScrollView(
child: Text(
comment != null && comment.isNotEmpty
child: _ShadowText(
text: comment != null && comment.isNotEmpty
? comment
: files[index.value].name,
style:
Theme.of(context).textTheme.bodyMedium?.copyWith(
shadows: [
Shadow(
blurRadius: 2.0,
color: Theme.of(context).canvasColor,
),
Shadow(
blurRadius: 2.0,
color: Theme.of(context).canvasColor,
),
],
),
),
),
),
Expand All @@ -237,3 +225,49 @@ class ImageGalleryDialog extends HookConsumerWidget {
);
}
}

class _ShadowText extends StatelessWidget {
const _ShadowText({required this.text});

final String text;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final shadowColor = theme.canvasColor;
final style = theme.textTheme.bodyMedium ?? const TextStyle();

if (defaultTargetPlatform == TargetPlatform.android) {
return Stack(
children: [
Text(
text,
style: style.copyWith(
foreground: Paint()
..color = shadowColor.withValues(alpha: 0.5)
..style = PaintingStyle.stroke
..strokeWidth = 2.0,
),
),
Text(text, style: style),
],
);
} else {
return Text(
text,
style: style.copyWith(
shadows: [
Shadow(
blurRadius: 2.0,
color: shadowColor,
),
Shadow(
blurRadius: 2.0,
color: shadowColor,
),
],
),
);
}
}
}
72 changes: 58 additions & 14 deletions lib/view/widget/instance_ticker_widget.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand Down Expand Up @@ -77,22 +78,11 @@ class InstanceTickerWidget extends ConsumerWidget {
Expanded(
child: Padding(
padding: const EdgeInsets.all(1.0),
child: Text(
instance != null
child: _ShadowText(
text: instance != null
? instance?.name ?? host ?? ''
: meta?.name ?? account.host,
style: style.copyWith(
color: Colors.white,
height: 1.0,
shadows: const [
Shadow(blurRadius: 2.0),
Shadow(blurRadius: 2.0),
Shadow(blurRadius: 2.0),
],
).copyWith(height: 1.0),
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 1,
style: style.copyWith(height: 1.0),
),
),
),
Expand All @@ -104,3 +94,57 @@ class InstanceTickerWidget extends ConsumerWidget {
);
}
}

class _ShadowText extends StatelessWidget {
const _ShadowText({
required this.text,
required this.style,
});

final String text;
final TextStyle style;

@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.android) {
return Stack(
children: [
Text(
text,
style: style.copyWith(
foreground: Paint()
..color = Colors.black38
..style = PaintingStyle.stroke
..strokeWidth = 2.0,
),
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 1,
),
Text(
text,
style: style.copyWith(color: Colors.white),
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 1,
),
],
);
} else {
return Text(
text,
style: style.copyWith(
color: Colors.white,
shadows: const [
Shadow(blurRadius: 2.0),
Shadow(blurRadius: 2.0),
Shadow(blurRadius: 2.0),
],
),
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 1,
);
}
}
}

0 comments on commit e558e7d

Please sign in to comment.