import 'dart:typed_data'; import 'package:flutter/material.dart'; import '../api/oa_client.dart'; import '../theme.dart'; class TencentMapThumb extends StatefulWidget { const TencentMapThumb({ super.key, required this.api, required this.lat, required this.lng, this.height = 110, this.width, }); final OaClient api; final double lat; final double lng; final double height; final double? width; @override State createState() => _TencentMapThumbState(); } class _TencentMapThumbState extends State { Uint8List? _bytes; @override void initState() { super.initState(); _load(); } @override void didUpdateWidget(covariant TencentMapThumb oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.lat != widget.lat || oldWidget.lng != widget.lng) _load(); } Future _load() async { final b = await widget.api.getBytes('/office/geo/static-map', query: { 'lat': '${widget.lat}', 'lng': '${widget.lng}', }); if (!mounted) return; setState(() => _bytes = b); } @override Widget build(BuildContext context) { if (_bytes != null) { return Image.memory(_bytes!, width: widget.width, height: widget.height, fit: BoxFit.cover); } return SizedBox( width: widget.width, height: widget.height, child: const ColoredBox( color: Color(0xFFE8F5E9), child: Center(child: Icon(Icons.place, color: kWeGreen, size: 32)), ), ); } }