fluttyui 0.0.1
fluttyui: ^0.0.1 copied to clipboard
Flutter UI toolkit for writing modern applications
example/lib/main.dart
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:fluttyui/fluttyui.dart';
import 'package:hugeicons/hugeicons.dart';
import 'package:shared_preferences/shared_preferences.dart';
// All application code, models, pages and persistence live in this file.
void main() => runApp(const DaybookApp());
class DaybookApp extends StatefulWidget {
const DaybookApp({super.key});
@override
State<DaybookApp> createState() => _DaybookAppState();
}
class _DaybookAppState extends State<DaybookApp> {
static const _storageKey = 'daybook.v1';
final _notes = TextEditorController(
text: 'A little room to think.\n\nWhat would make today a good day?',
);
final _noteTitle = TextEditingController(text: 'My daily notes');
List<_Task> _tasks = [
const _Task(
id: 'welcome',
title: 'Make room for your next idea',
details: 'Tap a task to edit its title, priority, and notes.',
priority: 'High',
),
const _Task(
id: 'plan',
title: 'Write down three things for today',
details: 'Use New task to add your own. Everything saves on this device.',
),
const _Task(
id: 'notes',
title: 'Try the notes editor',
details: 'Open Notes and use the formatting toolbar.',
),
const _Task(
id: 'theme',
title: 'Find a color that feels like you',
details: 'Appearance has brand colors and light/dark modes.',
done: true,
),
];
ThemeMode _mode = ThemeMode.system;
int _brand = 0;
bool _loading = true;
String? _saveError;
SharedPreferences? _preferences;
Future<void> _writes = Future.value();
@override
void initState() {
super.initState();
unawaited(_load());
}
Future<void> _load() async {
try {
final preferences = await SharedPreferences.getInstance();
final stored = preferences.getString(_storageKey);
if (stored != null) {
final data = jsonDecode(stored) as Map<String, dynamic>;
final tasks = (data['tasks'] as List<dynamic>)
.map((v) => _Task.fromJson(v as Map<String, dynamic>))
.toList();
final mode = ThemeMode.values.firstWhere(
(m) => m.name == data['mode'],
orElse: () => ThemeMode.system,
);
final brand = (data['brand'] as int? ?? 0).clamp(0, _brands.length - 1);
final title = data['noteTitle'] as String? ?? 'My daily notes';
final document = data['notes'] as Map<String, dynamic>?;
if (document != null) _notes.loadDocument(document);
_tasks = tasks;
_mode = mode;
_brand = brand;
_noteTitle.text = title;
}
_preferences = preferences;
} on Object {
_saveError = 'Could not restore saved data. Your current changes can still be saved.';
}
if (mounted) setState(() => _loading = false);
}
void _save() {
final snapshot = jsonEncode({
'tasks': _tasks.map((task) => task.toJson()).toList(),
'mode': _mode.name,
'brand': _brand,
'noteTitle': _noteTitle.text,
'notes': _notes.toDocument(),
});
// Serialize writes so an older draft cannot overwrite a newer one.
_writes = _writes.then((_) async {
try {
final preferences = _preferences ??=
await SharedPreferences.getInstance();
if (!await preferences.setString(_storageKey, snapshot)) {
throw StateError('Save failed');
}
if (mounted && _saveError != null) setState(() => _saveError = null);
} on Object {
if (mounted) {
setState(
() => _saveError =
'Changes are in memory. Local saving failed; tap Retry.',
);
}
}
});
}
void _updateTasks(List<_Task> tasks) {
setState(() => _tasks = tasks);
_save();
}
@override
void dispose() {
_notes.dispose();
_noteTitle.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final brand = _brands[_brand].$2;
return FluttyApp(
title: 'Daybook',
themeMode: _mode,
theme: ThemeData(colors: ColorTokens(brand: brand)),
darkTheme: ThemeData.dark(colors: ColorTokens.dark(brand: brand)),
home: _loading
? const Center(child: Spinner())
: _DaybookHome(
tasks: _tasks,
notes: _notes,
noteTitle: _noteTitle,
onTasksChanged: _updateTasks,
onNotesChanged: _save,
mode: _mode,
brand: _brand,
onModeChanged: (mode) {
setState(() => _mode = mode);
_save();
},
onBrandChanged: (brand) {
setState(() => _brand = brand);
_save();
},
saveError: _saveError,
onRetry: _save,
),
);
}
}
const _brands = <(String, Color)>[
('Ocean', Color(0xFF087CF0)),
('Violet', Color(0xFF7C3AED)),
('Rose', Color(0xFFDB2777)),
('Forest', Color(0xFF15803D)),
];
class _Task {
const _Task({
required this.id,
required this.title,
this.details = '',
this.priority = 'Normal',
this.done = false,
});
factory _Task.fromJson(Map<String, dynamic> data) => _Task(
id: data['id'] as String,
title: data['title'] as String,
details: data['details'] as String? ?? '',
priority: data['priority'] as String? ?? 'Normal',
done: data['done'] as bool? ?? false,
);
final String id;
final String title;
final String details;
final String priority;
final bool done;
_Task toggle() => _Task(
id: id,
title: title,
details: details,
priority: priority,
done: !done,
);
Map<String, dynamic> toJson() => {
'id': id,
'title': title,
'details': details,
'priority': priority,
'done': done,
};
}
class _DaybookHome extends StatefulWidget {
const _DaybookHome({
required this.tasks,
required this.notes,
required this.noteTitle,
required this.onTasksChanged,
required this.onNotesChanged,
required this.mode,
required this.brand,
required this.onModeChanged,
required this.onBrandChanged,
required this.saveError,
required this.onRetry,
});
final List<_Task> tasks;
final TextEditorController notes;
final TextEditingController noteTitle;
final ValueChanged<List<_Task>> onTasksChanged;
final VoidCallback onNotesChanged;
final ThemeMode mode;
final int brand;
final ValueChanged<ThemeMode> onModeChanged;
final ValueChanged<int> onBrandChanged;
final String? saveError;
final VoidCallback onRetry;
@override
State<_DaybookHome> createState() => _DaybookHomeState();
}
class _DaybookHomeState extends State<_DaybookHome> {
final _search = TextEditingController();
int _page = 0;
int _filter = 0;
@override
void dispose() {
Toast.dismiss();
_search.dispose();
super.dispose();
}
void _notify(
String title, {
String? description,
ToastVariant variant = ToastVariant.success,
}) {
Toast.show(
context,
title: description == null ? null : title,
message: description ?? title,
variant: variant,
);
}
void _showToastExample(ToastVariant variant, {bool longMessage = false}) {
final (title, message) = switch (variant) {
ToastVariant.defaultVariant => (
'Join a team',
'Junior Garcia sent you an invitation to join your team!',
),
ToastVariant.accent => (
'You have 2 credits left',
'Get a paid plan for more credits',
),
ToastVariant.success => (
'Your changes are saved',
'Everything is up to date on this device.',
),
ToastVariant.warning => (
'Storage is almost full',
'Review your files to make room for new work.',
),
ToastVariant.danger => (
'Storage is full',
longMessage
? 'Remove files to release space. You can archive older documents, delete unused attachments, or move your files to another location. Longer messages wrap while the Close button stays at the top.'
: 'Remove files to release space.',
),
};
Toast.show(
context,
title: title,
message: message,
variant: variant,
duration: const Duration(seconds: 6),
);
}
Future<void> _editTask([_Task? task]) async {
final motion = context.theme.motion.resolve(
context,
preset: MotionPreset.navigation,
);
final result = await Navigator.of(context).push<_TaskResult>(
PageRouteBuilder(
transitionDuration: motion.duration,
reverseTransitionDuration: motion.duration,
pageBuilder: (_, animation, secondaryAnimation) =>
_TaskEditor(task: task),
transitionsBuilder: (_, animation, secondaryAnimation, child) =>
FadeTransition(
opacity: animation.drive(CurveTween(curve: motion.curve)),
child: child,
),
),
);
if (!mounted || result == null) return;
final tasks = [...widget.tasks];
if (result.deleted) {
tasks.removeWhere((item) => item.id == task?.id);
_notify(
'Task deleted',
description: 'The task was removed from your workspace.',
variant: ToastVariant.defaultVariant,
);
} else {
final updated = result.task!;
final index = tasks.indexWhere((item) => item.id == updated.id);
if (index < 0) {
tasks.insert(0, updated);
} else {
tasks[index] = updated;
}
_notify(
task == null ? 'Task added' : 'Task updated',
description: 'Your task has been saved on this device.',
);
}
widget.onTasksChanged(tasks);
}
Future<void> _copyNote() async {
try {
await Clipboard.setData(
ClipboardData(text: '${widget.noteTitle.text}\n\n${widget.notes.text}'),
);
if (mounted) {
_notify(
'Note copied to clipboard',
description: 'Paste it into an email or another document.',
);
}
} on Object {
if (mounted) {
_notify(
'Clipboard is unavailable',
description: 'Please try copying your note again.',
variant: ToastVariant.danger,
);
}
}
}
@override
Widget build(BuildContext context) {
final theme = context.theme;
return SafeArea(
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 900),
child: Padding(
padding: const EdgeInsets.fromLTRB(20, 18, 20, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Container(
width: 38,
height: 38,
decoration: BoxDecoration(
color: theme.colors.brand,
borderRadius: BorderRadius.circular(13),
),
child: const Center(
child: HugeIcon(
icon: HugeIcons.strokeRoundedCheck,
size: 22,
color: Color(0xFFFFFFFF),
),
),
),
const SizedBox(width: 10),
const Expanded(
child: Text(
'daybook',
style: TextStyle(
fontSize: 21,
fontWeight: FontWeight.w700,
letterSpacing: -.7,
),
),
),
Text(
'YOUR LITTLE WORKSPACE',
style: TextStyle(
fontSize: 9,
letterSpacing: 1,
color: theme.colors.muted,
),
),
],
),
const SizedBox(height: 22),
if (widget.saveError != null)
_Notice(
message: widget.saveError!,
action: 'Retry',
onTap: widget.onRetry,
),
Expanded(
child: IndexedStack(
index: _page,
children: [
_tasksPage(theme),
_notesPage(theme),
_appearancePage(theme),
],
),
),
const SizedBox(height: 12),
_segments(
theme,
selected: _page,
labels: const ['Tasks', 'Notes', 'Appearance'],
onChanged: (index) {
FocusManager.instance.primaryFocus?.unfocus();
setState(() => _page = index);
},
),
],
),
),
),
),
);
}
Widget _tasksPage(ThemeData theme) => LayoutBuilder(
builder: (context, constraints) {
final done = widget.tasks.where((task) => task.done).length;
final query = _search.text.trim().toLowerCase();
final filtered = widget.tasks
.where(
(task) =>
(_filter == 0 || (_filter == 1 ? !task.done : task.done)) &&
'${task.title} ${task.details}'.toLowerCase().contains(query),
)
.toList();
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (constraints.maxHeight < 500)
Padding(
padding: const EdgeInsets.only(bottom: 14),
child: Row(
children: [
const Expanded(
child: Text(
'Your tasks',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w600,
),
),
),
Text(
'${widget.tasks.length - done} to do',
style: TextStyle(fontSize: 12, color: theme.colors.muted),
),
],
),
)
else ...[
const _PageHeading(
title: 'Make today count.',
subtitle: 'A clear head starts with a little list.',
),
Row(
children: [
Expanded(
child: _Stat(
value: '${widget.tasks.length - done}',
label: 'To do',
color: theme.colors.brand,
),
),
const SizedBox(width: 10),
Expanded(
child: _Stat(
value: '$done',
label: 'Completed',
color: theme.colors.success,
),
),
],
),
],
const SizedBox(height: 16),
SearchField<String>(
controller: _search,
hintText: 'Find a task...',
onChanged: (_) => setState(() {}),
),
const SizedBox(height: 12),
_segments(
theme,
selected: _filter,
labels: const ['All', 'To do', 'Done'],
onChanged: (i) => setState(() => _filter = i),
),
const SizedBox(height: 12),
Expanded(
child: ScrollShadow(
size: 28,
child: filtered.isEmpty
? ListView(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 36),
child: Column(
children: [
HugeIcon(
icon: HugeIcons.strokeRoundedCheck,
size: 28,
color: theme.colors.muted,
),
const SizedBox(height: 12),
Text(
query.isEmpty
? 'All clear here.'
: 'No matching tasks',
style: const TextStyle(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 6),
Text(
query.isEmpty
? 'Add a task to get started.'
: 'Try another search or filter.',
style: TextStyle(color: theme.colors.muted),
),
],
),
),
],
)
: ListView.separated(
padding: const EdgeInsets.symmetric(vertical: 4),
itemCount: filtered.length,
separatorBuilder: (_, index) => const SizedBox(height: 9),
itemBuilder: (_, index) {
final task = filtered[index];
return SwipeableRow(
key: ValueKey(task.id),
borderRadius: BorderRadius.circular(
theme.radius.surface,
),
startActions: [
SwipeableRowAction(
label: task.done ? 'Undo' : 'Done',
icon: HugeIcon(
icon: HugeIcons.strokeRoundedCheck,
color: theme.colors.foreground,
),
variant: SwipeableRowActionVariant.success,
onPressed: () => widget.onTasksChanged(
widget.tasks
.map(
(item) => item.id == task.id
? item.toggle()
: item,
)
.toList(),
),
),
],
endActions: [
SwipeableRowAction(
label: 'Edit',
icon: HugeIcon(
icon: HugeIcons.strokeRoundedPencilEdit02,
color: theme.colors.foreground,
),
onPressed: () => _editTask(task),
),
SwipeableRowAction(
label: 'Delete',
icon: HugeIcon(
icon: HugeIcons.strokeRoundedDelete02,
color: theme.colors.onBrand,
),
variant: SwipeableRowActionVariant.danger,
onPressed: () {
widget.onTasksChanged(
widget.tasks
.where((item) => item.id != task.id)
.toList(),
);
_notify(
'Task deleted',
description: 'The task was removed from your workspace.',
variant: ToastVariant.defaultVariant,
);
},
),
],
child: Surface(
padding: const EdgeInsets.all(16),
elevation: 0,
child: Row(
children: [
Checkbox(
value: task.done,
activeColor: theme.colors.brand,
borderColor: theme.colors.border,
onChanged: (_) => widget.onTasksChanged(
widget.tasks
.map(
(item) => item.id == task.id
? item.toggle()
: item,
)
.toList(),
),
),
const SizedBox(width: 14),
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _editTask(task),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
task.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.w500,
color: task.done
? theme.colors.muted
: theme.colors.foreground,
decoration: task.done
? TextDecoration.lineThrough
: TextDecoration.none,
),
),
const SizedBox(height: 5),
Text(
task.priority == 'High'
? 'High priority'
: 'Personal',
style: TextStyle(
fontSize: 11,
color: task.priority == 'High'
? theme.colors.brand
: theme.colors.muted,
),
),
],
),
),
),
_IconAction(
label: 'Edit ${task.title}',
icon: HugeIcons.strokeRoundedChevronRight,
onTap: () => _editTask(task),
),
],
),
),
);
},
),
),
),
const SizedBox(height: 12),
Button(
text: 'New task',
leading: HugeIcon(
icon: HugeIcons.strokeRoundedPlusSign,
size: 16,
color: theme.colors.onBrand,
),
isFullWidth: true,
onPressed: () => _editTask(),
),
],
);
},
);
Widget _notesPage(ThemeData theme) => ScrollShadow(
child: ListView(
children: [
const _PageHeading(
title: 'Room to think.',
subtitle: 'Capture a thought. Shape it into something.',
),
Input(
controller: widget.noteTitle,
placeholder: 'Note title',
onChanged: (_) => widget.onNotesChanged(),
),
const SizedBox(height: 14),
TextEditor(
controller: widget.notes,
height: 380,
placeholder: 'What is on your mind?',
onChanged: (_) => widget.onNotesChanged(),
),
const SizedBox(height: 14),
Button(text: 'Copy note', onPressed: _copyNote),
const SizedBox(height: 12),
Text(
'Saved automatically on this device. Formatting is preserved.',
style: TextStyle(fontSize: 12, color: theme.colors.muted),
),
const SizedBox(height: 24),
],
),
);
Widget _appearancePage(ThemeData theme) => ScrollShadow(
child: ListView(
children: [
const _PageHeading(
title: 'Make it yours.',
subtitle: 'Same workspace. Your point of view.',
),
Surface(
elevation: 0,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Appearance',
style: TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 6),
Text(
'Follow your device or pick a mode.',
style: TextStyle(fontSize: 12, color: theme.colors.muted),
),
const SizedBox(height: 16),
_segments(
theme,
selected: widget.mode.index,
labels: const ['System', 'Light', 'Dark'],
onChanged: (i) => widget.onModeChanged(ThemeMode.values[i]),
),
const SizedBox(height: 26),
const Text(
'Brand color',
style: TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 14),
Wrap(
spacing: 12,
runSpacing: 12,
children: [
for (var i = 0; i < _brands.length; i++)
Semantics(
button: true,
selected: widget.brand == i,
label: _brands[i].$1,
child: GestureDetector(
onTap: () => widget.onBrandChanged(i),
child: Column(
children: [
Container(
width: 42,
height: 42,
decoration: BoxDecoration(
color: _brands[i].$2,
shape: BoxShape.circle,
),
child: widget.brand == i
? const Center(
child: HugeIcon(
icon: HugeIcons.strokeRoundedCheck,
size: 20,
color: Color(0xFFFFFFFF),
),
)
: null,
),
const SizedBox(height: 6),
Text(
_brands[i].$1,
style: TextStyle(
fontSize: 11,
color: theme.colors.muted,
),
),
],
),
),
),
],
),
],
),
),
const SizedBox(height: 16),
Surface(
elevation: 0,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Toasts',
style: TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 6),
Text(
'Try the variants or preview a longer message.',
style: TextStyle(fontSize: 12, color: theme.colors.muted),
),
const SizedBox(height: 14),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (final (label, variant) in const [
('Default', ToastVariant.defaultVariant),
('Accent', ToastVariant.accent),
('Success', ToastVariant.success),
('Warning', ToastVariant.warning),
('Danger', ToastVariant.danger),
])
Button(
text: label,
size: ButtonSize.sm,
backgroundColor: theme.colors.surfaceTertiary,
foregroundColor: theme.colors.brand,
onPressed: () => _showToastExample(variant),
),
Button(
text: 'Long message',
size: ButtonSize.sm,
backgroundColor: theme.colors.surfaceTertiary,
foregroundColor: theme.colors.brand,
onPressed: () => _showToastExample(
ToastVariant.danger,
longMessage: true,
),
),
Button(
text: 'Hide toast',
size: ButtonSize.sm,
backgroundColor: theme.colors.danger.withValues(alpha: .12),
foregroundColor: theme.colors.danger,
onPressed: Toast.dismiss,
),
],
),
],
),
),
const SizedBox(height: 16),
Surface(
elevation: 0,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'A small app, built with FluttyUI',
style: TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 8),
Text(
'Inter typography, token-based themes, rounded surfaces, editable tasks and rich-text notes. All application code is in one main.dart file.',
style: TextStyle(
fontSize: 13,
height: 1.6,
color: theme.colors.muted,
),
),
const SizedBox(height: 12),
Text(
'Your data stays on this device. No account or server needed.',
style: TextStyle(fontSize: 12, color: theme.colors.muted),
),
],
),
),
const SizedBox(height: 24),
],
),
);
}
Widget _segments(
ThemeData theme, {
required int selected,
required List<String> labels,
required ValueChanged<int> onChanged,
}) => Segment(
selectedIndex: selected,
expanded: true,
items: [for (final label in labels) SegmentItem(label: label)],
onChanged: onChanged,
backgroundColor: theme.colors.surfaceTertiary,
selectedColor: theme.colors.surface,
foregroundColor: theme.colors.muted,
selectedForegroundColor: theme.colors.foreground,
focusColor: theme.colors.brand,
);
class _TaskResult {
const _TaskResult({this.task, this.deleted = false});
final _Task? task;
final bool deleted;
}
class _TaskEditor extends StatefulWidget {
const _TaskEditor({this.task});
final _Task? task;
@override
State<_TaskEditor> createState() => _TaskEditorState();
}
class _TaskEditorState extends State<_TaskEditor> {
late final _title = TextEditingController(text: widget.task?.title ?? '');
late final _details = TextEditingController(text: widget.task?.details ?? '');
late String _priority = widget.task?.priority ?? 'Normal';
String? _error;
@override
void dispose() {
_title.dispose();
_details.dispose();
super.dispose();
}
void _save() {
if (_title.text.trim().isEmpty) {
setState(() => _error = 'Give your task a title.');
return;
}
Navigator.of(context).pop(
_TaskResult(
task: _Task(
id:
widget.task?.id ??
DateTime.now().microsecondsSinceEpoch.toString(),
title: _title.text.trim(),
details: _details.text.trim(),
priority: _priority,
done: widget.task?.done ?? false,
),
),
);
}
@override
Widget build(BuildContext context) {
final theme = context.theme;
return ColoredBox(
color: theme.colors.background,
child: SafeArea(
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 660),
child: Padding(
padding: EdgeInsets.fromLTRB(
20,
18,
20,
20 + MediaQuery.viewInsetsOf(context).bottom,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
_IconAction(
label: 'Back',
icon: HugeIcons.strokeRoundedArrowLeft01,
onTap: () => Navigator.of(context).pop(),
),
const SizedBox(width: 10),
Expanded(
child: Text(
widget.task == null ? 'New task' : 'Edit task',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
),
],
),
const SizedBox(height: 20),
Expanded(
child: ListView(
children: [
const Text(
'What needs doing?',
style: TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
Input(
controller: _title,
placeholder: 'e.g. Sketch a new idea',
onChanged: (_) {
if (_error != null) setState(() => _error = null);
},
),
if (_error != null)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
_error!,
style: TextStyle(
color: theme.colors.danger,
fontSize: 12,
),
),
),
const SizedBox(height: 24),
const Text(
'Priority',
style: TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
Select<String>(
value: _priority,
optionFontSize: 14,
options: const [
SelectOption(label: 'Normal', value: 'Normal'),
SelectOption(label: 'High', value: 'High'),
],
onChanged: (value) =>
setState(() => _priority = value),
),
const SizedBox(height: 24),
const Text(
'Notes',
style: TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
TextArea(
controller: _details,
placeholder: 'Add a little context...',
minLines: 4,
maxLines: 7,
),
const SizedBox(height: 24),
],
),
),
Button(
text: 'Save task',
isFullWidth: true,
onPressed: _save,
),
if (widget.task != null) ...[
const SizedBox(height: 10),
Button(
text: 'Delete task',
backgroundColor: theme.colors.surface,
foregroundColor: theme.colors.danger,
isFullWidth: true,
onPressed: () =>
Navigator.of(context)
.pop(const _TaskResult(deleted: true)),
),
],
],
),
),
),
),
),
);
}
}
class _PageHeading extends StatelessWidget {
const _PageHeading({required this.title, required this.subtitle});
final String title;
final String subtitle;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.w600,
letterSpacing: -1,
),
),
const SizedBox(height: 6),
Text(
subtitle,
style: TextStyle(color: context.theme.colors.muted, fontSize: 13),
),
],
),
);
}
class _Stat extends StatelessWidget {
const _Stat({required this.value, required this.label, required this.color});
final String value;
final String label;
final Color color;
@override
Widget build(BuildContext context) => Surface(
elevation: 0,
padding: const EdgeInsets.all(16),
child: Row(
children: [
Text(
value,
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.w600,
color: color,
),
),
const SizedBox(width: 10),
Expanded(
child: Text(
label,
style: TextStyle(fontSize: 12, color: context.theme.colors.muted),
),
),
],
),
);
}
class _IconAction extends StatelessWidget {
const _IconAction({
required this.label,
required this.icon,
required this.onTap,
});
final String label;
final List<List<dynamic>> icon;
final VoidCallback onTap;
@override
Widget build(BuildContext context) => Semantics(
button: true,
label: label,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: SizedBox(
width: 38,
height: 38,
child: Center(
child: HugeIcon(
icon: icon,
size: 18,
color: context.theme.colors.muted,
),
),
),
),
);
}
class _Notice extends StatelessWidget {
const _Notice({required this.message, this.action, this.onTap});
final String message;
final String? action;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Surface(
variant: SurfaceVariant.tertiary,
padding: const EdgeInsets.all(12),
elevation: 0,
child: Semantics(
liveRegion: true,
child: Row(
children: [
Expanded(
child: Text(message, style: const TextStyle(fontSize: 12)),
),
if (action != null)
GestureDetector(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.all(4),
child: Text(
action!,
style: TextStyle(
fontSize: 12,
color: context.theme.colors.brand,
),
),
),
),
],
),
),
),
);
}