181 lines
5.1 KiB
Dart
181 lines
5.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:pag/pag.dart';
|
|
import 'package:yumi/shared/data_sources/models/message/sc_floating_message.dart';
|
|
import 'package:yumi/ui_kit/widgets/room/floating/floating_lucky_gift_global_screen_widget.dart';
|
|
|
|
void main() {
|
|
runApp(const LuckyGiftGlobalFloatingPreviewApp());
|
|
}
|
|
|
|
class LuckyGiftGlobalFloatingPreviewApp extends StatelessWidget {
|
|
const LuckyGiftGlobalFloatingPreviewApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ScreenUtilInit(
|
|
designSize: const Size(375, 812),
|
|
minTextAdapt: true,
|
|
builder: (_, child) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: const _LuckyGiftGlobalFloatingPreviewPage(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _LuckyGiftGlobalFloatingPreviewPage extends StatelessWidget {
|
|
const _LuckyGiftGlobalFloatingPreviewPage();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
body: Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
child: Image.asset(_backgroundAsset, fit: BoxFit.cover),
|
|
),
|
|
Positioned(
|
|
left: 0,
|
|
top: 116.w,
|
|
child: FloatingLuckyGiftGlobalScreenWidget(
|
|
debugDisableAutoSlide: true,
|
|
message: SCFloatingMessage(
|
|
type: FloatingLuckyGiftGlobalScreenWidget.floatingType,
|
|
roomId: '1002900',
|
|
userName: 'Bajul',
|
|
userAvatarUrl: '',
|
|
coins: 1000,
|
|
multiple: 10,
|
|
),
|
|
onAnimationCompleted: () {},
|
|
),
|
|
),
|
|
Positioned(left: 0, top: 250.w, child: const _PagLayerScanner()),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
const _backgroundAsset = 'sc_images/room/background_examples/bg_example_1.png';
|
|
|
|
class _PagLayerScanner extends StatefulWidget {
|
|
const _PagLayerScanner();
|
|
|
|
@override
|
|
State<_PagLayerScanner> createState() => _PagLayerScannerState();
|
|
}
|
|
|
|
class _PagLayerScannerState extends State<_PagLayerScanner> {
|
|
final _pagKey = GlobalKey<PAGViewState>();
|
|
final _foundLayers = <String>{};
|
|
String _summary = 'loading PAG...';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: FloatingLuckyGiftGlobalScreenWidget.bannerWidth.w,
|
|
height: 160.w,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SizedBox(
|
|
width: FloatingLuckyGiftGlobalScreenWidget.bannerWidth.w,
|
|
height: FloatingLuckyGiftGlobalScreenWidget.bannerHeight.w,
|
|
child: PAGView.asset(
|
|
FloatingLuckyGiftGlobalScreenWidget.backgroundPagAssetPath,
|
|
key: _pagKey,
|
|
width: FloatingLuckyGiftGlobalScreenWidget.bannerWidth.w,
|
|
height: FloatingLuckyGiftGlobalScreenWidget.bannerHeight.w,
|
|
autoPlay: false,
|
|
initProgress: 0.35,
|
|
repeatCount: PAGView.REPEAT_COUNT_LOOP,
|
|
onInit: _scanLayers,
|
|
),
|
|
),
|
|
Container(
|
|
width: FloatingLuckyGiftGlobalScreenWidget.bannerWidth.w,
|
|
padding: EdgeInsets.all(6.w),
|
|
color: Colors.black.withValues(alpha: 0.65),
|
|
child: Text(
|
|
_summary,
|
|
maxLines: 4,
|
|
overflow: TextOverflow.ellipsis,
|
|
textScaler: TextScaler.noScaling,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 9.sp,
|
|
decoration: TextDecoration.none,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _scanLayers() async {
|
|
await Future<void>.delayed(const Duration(milliseconds: 200));
|
|
final state = _pagKey.currentState;
|
|
if (state == null) {
|
|
return;
|
|
}
|
|
final rawWidth = state.rawWidth;
|
|
final rawHeight = state.rawHeight;
|
|
debugPrint('[LuckyGiftPAG] rawSize=${rawWidth}x$rawHeight');
|
|
if (rawWidth <= 0 || rawHeight <= 0) {
|
|
return;
|
|
}
|
|
final sampleXs =
|
|
<double>[
|
|
40,
|
|
80,
|
|
120,
|
|
170,
|
|
220,
|
|
280,
|
|
340,
|
|
410,
|
|
480,
|
|
560,
|
|
640,
|
|
710,
|
|
].where((value) => value < rawWidth).toList();
|
|
final sampleYs =
|
|
<double>[
|
|
32,
|
|
58,
|
|
82,
|
|
104,
|
|
128,
|
|
158,
|
|
].where((value) => value < rawHeight).toList();
|
|
for (final y in sampleYs) {
|
|
for (final x in sampleXs) {
|
|
final layers = await state.getLayersUnderPoint(x, y);
|
|
if (layers.isEmpty) {
|
|
continue;
|
|
}
|
|
_foundLayers.addAll(layers.where((name) => name.trim().isNotEmpty));
|
|
debugPrint(
|
|
'[LuckyGiftPAG] point=(${x.toStringAsFixed(0)},'
|
|
'${y.toStringAsFixed(0)}) layers=$layers',
|
|
);
|
|
}
|
|
}
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
_summary =
|
|
'raw ${rawWidth.toStringAsFixed(0)}x'
|
|
'${rawHeight.toStringAsFixed(0)} layers: '
|
|
'${_foundLayers.join(', ')}';
|
|
});
|
|
}
|
|
}
|