Files
pipelines/app/test/features/changes/widget_hosts.dart
T

42 lines
1.4 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// The two platform hosts the Changes widget tests share: Material for
/// Android/desktop/web and Cupertino for iOS/macOS. They state the platform
/// explicitly instead of mutating a global debug override.
Widget materialHost(
Widget child, {
TextScaler scaler = TextScaler.noScaling,
Brightness brightness = Brightness.light,
}) {
return MaterialApp(
theme: ThemeData(brightness: brightness),
builder: (context, app) => MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: scaler),
child: app!,
),
home: Scaffold(body: child),
);
}
Widget cupertinoHost(
Widget child, {
TextScaler scaler = TextScaler.noScaling,
Brightness brightness = Brightness.light,
}) {
return CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
builder: (context, app) => Theme(
// The real app selects Cupertino by platform; the test host states it
// explicitly without changing a global debug override. The Theme wraps
// the Navigator so dialogs opened later resolve the same platform.
data: ThemeData(platform: TargetPlatform.iOS),
child: MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: scaler),
child: app!,
),
),
home: CupertinoPageScaffold(child: SafeArea(child: child)),
);
}