105 lines
2.9 KiB
Dart
105 lines
2.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/host.dart';
|
|
|
|
const templatesRefreshKey = ValueKey<String>('templates-refresh');
|
|
const templatesBackKey = ValueKey<String>('templates-back');
|
|
|
|
/// The screen's native chrome.
|
|
///
|
|
/// Standalone use keeps the host's own app bar with Back and Refresh. A shell
|
|
/// that already owns navigation passes [embedded], which drops the bar and
|
|
/// keeps Refresh at the top of the body.
|
|
class TemplatesFrame extends StatelessWidget {
|
|
const TemplatesFrame({
|
|
super.key,
|
|
required this.body,
|
|
required this.embedded,
|
|
required this.canGoBack,
|
|
required this.refreshing,
|
|
required this.onBack,
|
|
required this.onRefresh,
|
|
});
|
|
|
|
final Widget body;
|
|
final bool embedded;
|
|
final bool canGoBack;
|
|
final bool refreshing;
|
|
final VoidCallback onBack;
|
|
final VoidCallback onRefresh;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (embedded) return _embedded(context);
|
|
return usesCupertinoHost(context)
|
|
? _cupertino(context)
|
|
: _material(context);
|
|
}
|
|
|
|
Widget _embedded(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Align(
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: _refreshButton(context),
|
|
),
|
|
),
|
|
Expanded(child: body),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _cupertino(BuildContext context) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
leading: canGoBack
|
|
? CupertinoButton(
|
|
key: templatesBackKey,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onBack,
|
|
child: const Icon(CupertinoIcons.back, semanticLabel: 'Back'),
|
|
)
|
|
: null,
|
|
middle: const Text('Templates'),
|
|
trailing: _refreshButton(context),
|
|
),
|
|
child: SafeArea(child: body),
|
|
);
|
|
}
|
|
|
|
Widget _material(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Templates'),
|
|
leading: canGoBack
|
|
? BackButton(key: templatesBackKey, onPressed: onBack)
|
|
: null,
|
|
actions: [_refreshButton(context)],
|
|
),
|
|
body: SafeArea(child: body),
|
|
);
|
|
}
|
|
|
|
Widget _refreshButton(BuildContext context) {
|
|
final onPressed = refreshing ? null : onRefresh;
|
|
if (usesCupertinoHost(context)) {
|
|
return CupertinoButton(
|
|
key: templatesRefreshKey,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onPressed,
|
|
child: const Icon(CupertinoIcons.refresh, semanticLabel: 'Refresh'),
|
|
);
|
|
}
|
|
return IconButton(
|
|
key: templatesRefreshKey,
|
|
tooltip: 'Refresh',
|
|
onPressed: onPressed,
|
|
icon: const Icon(Icons.refresh),
|
|
);
|
|
}
|
|
}
|