Files
FlClash/test/helpers/test_app.dart
T
chen08209 ee6a49713a feat(ui): draw the app's own glyphs and redraw the theme page
Drops the Material compatibility bridge and the icon font.

Changelog: New app glyphs, empty states and theme page
2026-10-02 02:51:32 +08:00

55 lines
1.6 KiB
Dart

import 'package:fl_clash/common/common.dart';
import 'package:fl_clash/common/theme.dart';
import 'package:fl_clash/l10n/l10n.dart';
import 'package:fl_clash/state.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
class TestApp extends StatelessWidget {
final Widget child;
final bool includeNavigatorKey;
final bool setTheme;
final bool wrapInProviderScope;
final List<Override> overrides;
final Widget Function(Widget child) homeBuilder;
final Locale? locale;
const TestApp({
super.key,
required this.child,
this.includeNavigatorKey = true,
this.setTheme = true,
this.wrapInProviderScope = false,
this.overrides = const [],
this.homeBuilder = _identity,
this.locale,
});
static Widget _identity(Widget child) => child;
@override
Widget build(BuildContext context) {
final app = MaterialApp(
navigatorKey: includeNavigatorKey ? globalState.navigatorKey : null,
locale: locale,
localizationsDelegates: const [
AppLocalizations.delegate,
...GlobalMaterialLocalizations.delegates,
],
supportedLocales: AppLocalizations.delegate.supportedLocales,
builder: (context, child) {
globalState.measure = Measure.of(context, 1);
if (setTheme) {
globalState.theme = CommonTheme.of(context, 1);
}
return child!;
},
home: homeBuilder(child),
);
return overrides.isNotEmpty || wrapInProviderScope
? ProviderScope(overrides: overrides, child: app)
: app;
}
}