mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 10:37:22 +03:00
feat(mobile): html text (#25739)
* feat: html text * feat: mobile ui showcase (#25827) * feat: mobile ui showcase * remove showcase from main app * update fonts * update code to be loaded from asset * fix ci --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> # Conflicts: # mobile/lib/widgets/common/immich_sliver_app_bar.dart --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ComponentExamples extends StatelessWidget {
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final List<Widget> examples;
|
||||
final bool expand;
|
||||
|
||||
const ComponentExamples({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
required this.examples,
|
||||
this.expand = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(10, 24, 24, 24),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: _PageHeader(title: title, subtitle: subtitle),
|
||||
),
|
||||
const SliverPadding(padding: EdgeInsets.only(top: 24)),
|
||||
if (expand)
|
||||
SliverList.builder(
|
||||
itemCount: examples.length,
|
||||
itemBuilder: (context, index) => examples[index],
|
||||
)
|
||||
else
|
||||
SliverLayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return SliverList.builder(
|
||||
itemCount: examples.length,
|
||||
itemBuilder: (context, index) => Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: constraints.crossAxisExtent * 0.6,
|
||||
maxWidth: constraints.crossAxisExtent,
|
||||
),
|
||||
child: IntrinsicWidth(child: examples[index]),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PageHeader extends StatelessWidget {
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
|
||||
const _PageHeader({required this.title, this.subtitle});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.headlineLarge?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (subtitle != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
subtitle!,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
237
mobile/packages/ui/showcase/lib/widgets/example_card.dart
Normal file
237
mobile/packages/ui/showcase/lib/widgets/example_card.dart
Normal file
@@ -0,0 +1,237 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:showcase/constants.dart';
|
||||
import 'package:syntax_highlight/syntax_highlight.dart';
|
||||
|
||||
late final Highlighter _codeHighlighter;
|
||||
|
||||
Future<void> initializeCodeHighlighter() async {
|
||||
await Highlighter.initialize(['dart']);
|
||||
final darkTheme = await HighlighterTheme.loadFromAssets([
|
||||
'assets/themes/github_dark.json',
|
||||
], const TextStyle(color: Color(0xFFe1e4e8)));
|
||||
|
||||
_codeHighlighter = Highlighter(language: 'dart', theme: darkTheme);
|
||||
}
|
||||
|
||||
class ExampleCard extends StatefulWidget {
|
||||
final String title;
|
||||
final String? description;
|
||||
final Widget preview;
|
||||
final String? code;
|
||||
|
||||
const ExampleCard({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.description,
|
||||
required this.preview,
|
||||
this.code,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ExampleCard> createState() => _ExampleCardState();
|
||||
}
|
||||
|
||||
class _ExampleCardState extends State<ExampleCard> {
|
||||
bool _showPreview = true;
|
||||
String? code;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.code != null) {
|
||||
rootBundle
|
||||
.loadString('lib/pages/components/examples/${widget.code!}')
|
||||
.then((value) {
|
||||
setState(() {
|
||||
code = value;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
elevation: 1,
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.title,
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
if (widget.description != null)
|
||||
Text(
|
||||
widget.description!,
|
||||
style: Theme.of(context).textTheme.bodyMedium
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (code != null) ...[
|
||||
const SizedBox(width: 16),
|
||||
Row(
|
||||
children: [
|
||||
_ToggleButton(
|
||||
icon: Icons.visibility_rounded,
|
||||
label: 'Preview',
|
||||
isSelected: _showPreview,
|
||||
onTap: () => setState(() => _showPreview = true),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_ToggleButton(
|
||||
icon: Icons.code_rounded,
|
||||
label: 'Code',
|
||||
isSelected: !_showPreview,
|
||||
onTap: () => setState(() => _showPreview = false),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
if (_showPreview)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SizedBox(width: double.infinity, child: widget.preview),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
width: double.infinity,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFF24292e),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(
|
||||
LayoutConstants.borderRadiusMedium,
|
||||
),
|
||||
bottomRight: Radius.circular(
|
||||
LayoutConstants.borderRadiusMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: _CodeCard(code: code!),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ToggleButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final bool isSelected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _ToggleButton({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.isSelected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(24)),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.7)
|
||||
: Theme.of(context).colorScheme.primary,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(24)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 16,
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CodeCard extends StatelessWidget {
|
||||
final String code;
|
||||
|
||||
const _CodeCard({required this.code});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final lines = code.split('\n');
|
||||
final lineNumberColor = Colors.white.withValues(alpha: 0.4);
|
||||
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 12, top: 8, bottom: 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: List.generate(
|
||||
lines.length,
|
||||
(index) => SizedBox(
|
||||
height: 20,
|
||||
child: Text(
|
||||
'${index + 1}',
|
||||
style: TextStyle(
|
||||
fontFamily: 'GoogleSansCode',
|
||||
fontSize: 13,
|
||||
color: lineNumberColor,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
SelectableText.rich(
|
||||
_codeHighlighter.highlight(code),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'GoogleSansCode',
|
||||
fontSize: 13,
|
||||
height: 1.54,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
17
mobile/packages/ui/showcase/lib/widgets/page_title.dart
Normal file
17
mobile/packages/ui/showcase/lib/widgets/page_title.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PageTitle extends StatelessWidget {
|
||||
final String title;
|
||||
final Widget child;
|
||||
|
||||
const PageTitle({super.key, required this.title, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Title(
|
||||
title: '$title | @immich/ui',
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
59
mobile/packages/ui/showcase/lib/widgets/shell_layout.dart
Normal file
59
mobile/packages/ui/showcase/lib/widgets/shell_layout.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:showcase/constants.dart';
|
||||
import 'package:showcase/widgets/sidebar_navigation.dart';
|
||||
|
||||
class ShellLayout extends StatelessWidget {
|
||||
final Widget child;
|
||||
final VoidCallback onThemeToggle;
|
||||
|
||||
const ShellLayout({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.onThemeToggle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Image.asset('assets/immich_logo.png', height: 32, width: 32),
|
||||
const SizedBox(width: 8),
|
||||
Image.asset(
|
||||
isDark
|
||||
? 'assets/immich-text-dark.png'
|
||||
: 'assets/immich-text-light.png',
|
||||
height: 24,
|
||||
filterQuality: FilterQuality.none,
|
||||
isAntiAlias: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
isDark ? Icons.light_mode_outlined : Icons.dark_mode_outlined,
|
||||
size: LayoutConstants.iconSizeLarge,
|
||||
),
|
||||
onPressed: onThemeToggle,
|
||||
tooltip: 'Toggle theme',
|
||||
),
|
||||
],
|
||||
shape: Border(
|
||||
bottom: BorderSide(color: Theme.of(context).dividerColor, width: 1),
|
||||
),
|
||||
),
|
||||
body: Row(
|
||||
children: [
|
||||
const SidebarNavigation(),
|
||||
const VerticalDivider(),
|
||||
Expanded(child: child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
117
mobile/packages/ui/showcase/lib/widgets/sidebar_navigation.dart
Normal file
117
mobile/packages/ui/showcase/lib/widgets/sidebar_navigation.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:showcase/constants.dart';
|
||||
import 'package:showcase/routes.dart';
|
||||
|
||||
class SidebarNavigation extends StatelessWidget {
|
||||
const SidebarNavigation({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: LayoutConstants.sidebarWidth,
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surface),
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
|
||||
children: [
|
||||
...routesByCategory.entries.expand((entry) {
|
||||
final category = entry.key;
|
||||
final routes = entry.value;
|
||||
return [
|
||||
if (category != AppRouteCategory.root) _CategoryHeader(category),
|
||||
...routes.map((route) => _NavItem(route)),
|
||||
const SizedBox(height: 24),
|
||||
];
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategoryHeader extends StatelessWidget {
|
||||
final AppRouteCategory category;
|
||||
|
||||
const _CategoryHeader(this.category);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 12, top: 8, bottom: 8),
|
||||
child: Text(
|
||||
category.displayName,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NavItem extends StatelessWidget {
|
||||
final AppRoute route;
|
||||
|
||||
const _NavItem(this.route);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final currentRoute = GoRouterState.of(context).uri.toString();
|
||||
final isSelected = currentRoute == route.path;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
context.go(route.path);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(
|
||||
LayoutConstants.borderRadiusMedium,
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? (isDark
|
||||
? Colors.white.withValues(alpha: 0.1)
|
||||
: Theme.of(
|
||||
context,
|
||||
).colorScheme.primaryContainer.withValues(alpha: 0.5))
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(
|
||||
LayoutConstants.borderRadiusMedium,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
route.icon,
|
||||
size: 20,
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
route.name,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user