mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-22 10:24:28 +10:00
feat(chat): add global pinch-to-zoom text scaling via ChatTextScaleService
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user