feat(chat): add global pinch-to-zoom text scaling via ChatTextScaleService

This commit is contained in:
just_stuff_tm
2026-02-23 22:41:32 -05:00
parent 64bf307d09
commit 0f17e2382c
5 changed files with 247 additions and 92 deletions
+45
View File
@@ -0,0 +1,45 @@
import 'package:flutter/foundation.dart';
import '../storage/prefs_manager.dart';
/// Client-side accessibility/UI service that exposes a persistent shared text scale
/// factor. No MeshCoreConnector/RoomServer or protocol interaction occurs, and the
/// value is saved locally via SharedPreferences so it can be reused in Markdown
/// viewers, log panels, or other text-heavy widgets without redundant network
/// dependencies.
///
/// Widgets should scope rebuilds using the snippet below so only the scaled text
/// is rebuilt instead of the entire chat list:
/// ```dart
/// context.select<ChatTextScaleService, double>(
/// (service) => service.scale,
/// )
/// ```
class ChatTextScaleService extends ChangeNotifier {
static const _prefKey = 'chat_text_scale';
static const double _minScale = 0.8;
static const double _maxScale = 1.8;
double _scale = 1.0;
double get scale => _scale;
Future<void> initialize() async {
final stored = PrefsManager.instance.getDouble(_prefKey);
if (stored != null) {
_scale = _clamp(stored);
}
}
void setScale(double value) {
final next = _clamp(value);
if (next == _scale) return;
_scale = next;
PrefsManager.instance.setDouble(_prefKey, _scale);
notifyListeners();
}
void reset() => setScale(1.0);
double _clamp(double value) => value.clamp(_minScale, _maxScale).toDouble();
}