// harness.dart — 测试公共脚手架 import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:pangolin_vpn/pangolin_theme.dart'; /// 测试环境禁用 google_fonts 运行时网络拉取(离线确定化)。 /// /// 注意:golden 测试需要实际渲染字体。如果字体未提前下载/缓存, /// 禁用网络拉取会导致 google_fonts 抛出异常。 /// 因此此函数仅在非 golden 的行为型测试中调用(widgets_test / unit)。 void disableGoogleFontsFetching() { GoogleFonts.config.allowRuntimeFetching = false; } /// Golden 测试专用:允许 google_fonts 从网络/缓存加载字体。 /// 首次运行会下载并缓存字体,后续离线运行时从缓存读取。 void enableGoogleFontsFetching() { GoogleFonts.config.allowRuntimeFetching = true; } /// 用穿山甲明/暗主题包裹被测组件,并固定宽度便于 golden 对照。 Widget wrapThemed( Widget child, { bool dark = false, double width = 360, List overrides = const [], }) { return ProviderScope( overrides: overrides, child: MaterialApp( debugShowCheckedModeBanner: false, theme: PangolinTheme.light, darkTheme: PangolinTheme.dark, themeMode: dark ? ThemeMode.dark : ThemeMode.light, home: Scaffold( body: Center( child: SizedBox(width: width, child: child), ), ), ), ); }