design.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. /// Semantic color tokens from DESIGN.md (light appearance).
  4. class ScribeColors {
  5. static const Color canvas = Color(0xFFF2F2F7);
  6. static const Color surface = Color(0xFFFFFFFF);
  7. static const Color primaryText = Color(0xFF1C1C1E);
  8. static const Color secondaryText = Color(0xFF63636B);
  9. static const Color tertiaryText = Color(0xFF74747C);
  10. static const Color accent = Color(0xFF0066D6);
  11. static const Color accentText = Color(0xFF005BC4);
  12. static const Color accentSoft = Color(0xFFE8F1FF);
  13. static const Color separator = Color(0xFFE5E5EA);
  14. static const Color strongSeparator = Color(0xFFC7C7CC);
  15. static const Color success = Color(0xFF248A3D);
  16. static const Color danger = Color(0xFFC9342D);
  17. static const Color warningSurface = Color(0xFFFFEBE9);
  18. static const Color infoSurface = Color(0xFFE8F1FF);
  19. }
  20. /// Layout constants from DESIGN.md.
  21. class ScribeSpacing {
  22. static const double screenMargin = 20;
  23. static const double panelPadding = 16;
  24. static const double majorSectionGap = 26;
  25. static const double relatedGap = 10;
  26. static const double panelRadius = 20;
  27. static const double controlRadius = 12;
  28. static const double minTarget = 44;
  29. }
  30. /// Type scale from DESIGN.md. Platform sans-serif; never clamp text scale.
  31. class ScribeType {
  32. static const TextStyle hero = TextStyle(
  33. fontSize: 34, fontWeight: FontWeight.bold, color: ScribeColors.primaryText);
  34. static const TextStyle section = TextStyle(
  35. fontSize: 28,
  36. fontWeight: FontWeight.w600,
  37. color: ScribeColors.primaryText);
  38. static const TextStyle wordmark = TextStyle(
  39. fontSize: 22, fontWeight: FontWeight.bold, color: ScribeColors.primaryText);
  40. static const TextStyle title = TextStyle(
  41. fontSize: 17,
  42. fontWeight: FontWeight.w600,
  43. color: ScribeColors.primaryText);
  44. static const TextStyle body =
  45. TextStyle(fontSize: 16, color: ScribeColors.primaryText);
  46. static const TextStyle metadata =
  47. TextStyle(fontSize: 13, color: ScribeColors.secondaryText);
  48. static const TextStyle sectionLabel = TextStyle(
  49. fontSize: 12, color: ScribeColors.tertiaryText, height: 1.1);
  50. }
  51. ThemeData scribeTheme() {
  52. final base = ThemeData(
  53. brightness: Brightness.light,
  54. useMaterial3: true,
  55. );
  56. return base.copyWith(
  57. scaffoldBackgroundColor: ScribeColors.canvas,
  58. colorScheme: const ColorScheme.light(
  59. primary: ScribeColors.accent,
  60. secondary: ScribeColors.accent,
  61. surface: ScribeColors.surface,
  62. error: ScribeColors.danger,
  63. ),
  64. textTheme: base.textTheme.apply(
  65. bodyColor: ScribeColors.primaryText,
  66. displayColor: ScribeColors.primaryText,
  67. ),
  68. inputDecorationTheme: InputDecorationTheme(
  69. filled: true,
  70. fillColor: ScribeColors.surface,
  71. border: OutlineInputBorder(
  72. borderRadius: BorderRadius.circular(ScribeSpacing.controlRadius),
  73. borderSide: const BorderSide(color: ScribeColors.strongSeparator),
  74. ),
  75. enabledBorder: OutlineInputBorder(
  76. borderRadius: BorderRadius.circular(ScribeSpacing.controlRadius),
  77. borderSide: const BorderSide(color: ScribeColors.strongSeparator),
  78. ),
  79. focusedBorder: OutlineInputBorder(
  80. borderRadius: BorderRadius.circular(ScribeSpacing.controlRadius),
  81. borderSide: const BorderSide(color: ScribeColors.accent, width: 2),
  82. ),
  83. ),
  84. snackBarTheme: const SnackBarThemeData(
  85. behavior: SnackBarBehavior.floating,
  86. backgroundColor: ScribeColors.primaryText,
  87. contentTextStyle: TextStyle(color: Colors.white),
  88. ),
  89. dialogTheme: DialogThemeData(
  90. backgroundColor: ScribeColors.surface,
  91. shape: RoundedRectangleBorder(
  92. borderRadius: BorderRadius.circular(ScribeSpacing.panelRadius),
  93. ),
  94. ),
  95. bottomSheetTheme: const BottomSheetThemeData(
  96. backgroundColor: ScribeColors.canvas,
  97. ),
  98. );
  99. }
  100. /// Opaque rounded surface, clipped to its bounds.
  101. class SurfacePanel extends StatelessWidget {
  102. const SurfacePanel({
  103. super.key,
  104. required this.child,
  105. this.padding = const EdgeInsets.all(ScribeSpacing.panelPadding),
  106. });
  107. final Widget child;
  108. final EdgeInsetsGeometry padding;
  109. @override
  110. Widget build(BuildContext context) {
  111. return Container(
  112. width: double.infinity,
  113. decoration: BoxDecoration(
  114. color: ScribeColors.surface,
  115. borderRadius: BorderRadius.circular(ScribeSpacing.panelRadius),
  116. ),
  117. clipBehavior: Clip.antiAlias,
  118. padding: padding,
  119. child: child,
  120. );
  121. }
  122. }
  123. /// Filled primary action or tinted secondary action. 44pt minimum target.
  124. class ScribeAction extends StatelessWidget {
  125. const ScribeAction({
  126. super.key,
  127. required this.label,
  128. this.onPressed,
  129. this.secondary = false,
  130. this.danger = false,
  131. this.busy = false,
  132. });
  133. final String label;
  134. final VoidCallback? onPressed;
  135. final bool secondary;
  136. final bool danger;
  137. final bool busy;
  138. @override
  139. Widget build(BuildContext context) {
  140. final Color fill = danger
  141. ? ScribeColors.danger
  142. : secondary
  143. ? ScribeColors.accentSoft
  144. : ScribeColors.accent;
  145. final Color foreground =
  146. danger ? Colors.white : secondary ? ScribeColors.accentText : Colors.white;
  147. return SizedBox(
  148. height: ScribeSpacing.minTarget,
  149. child: FilledButton(
  150. style: FilledButton.styleFrom(
  151. backgroundColor: fill,
  152. foregroundColor: foreground,
  153. disabledBackgroundColor: fill.withValues(alpha: 0.4),
  154. disabledForegroundColor: foreground.withValues(alpha: 0.6),
  155. shape: RoundedRectangleBorder(
  156. borderRadius: BorderRadius.circular(ScribeSpacing.controlRadius),
  157. ),
  158. ),
  159. onPressed: onPressed == null || busy ? null : onPressed,
  160. child: busy
  161. ? SizedBox(
  162. width: 20,
  163. height: 20,
  164. child: CircularProgressIndicator(
  165. strokeWidth: 2, color: foreground))
  166. : Text(label, style: ScribeType.title),
  167. ),
  168. );
  169. }
  170. }
  171. /// Selectable capsule with selected semantics and a 44pt target.
  172. class FilterPill extends StatelessWidget {
  173. const FilterPill({
  174. super.key,
  175. required this.label,
  176. required this.selected,
  177. required this.onTap,
  178. });
  179. final String label;
  180. final bool selected;
  181. final VoidCallback onTap;
  182. @override
  183. Widget build(BuildContext context) {
  184. return Semantics(
  185. selected: selected,
  186. button: true,
  187. child: InkWell(
  188. onTap: onTap,
  189. borderRadius: BorderRadius.circular(ScribeSpacing.minTarget / 2),
  190. child: Container(
  191. height: ScribeSpacing.minTarget - 4,
  192. alignment: Alignment.center,
  193. padding: const EdgeInsets.symmetric(horizontal: 12),
  194. decoration: BoxDecoration(
  195. color: selected ? ScribeColors.accent : ScribeColors.surface,
  196. borderRadius:
  197. BorderRadius.circular(ScribeSpacing.minTarget / 2),
  198. border: Border.all(
  199. color: selected ? ScribeColors.accent : ScribeColors.strongSeparator,
  200. ),
  201. ),
  202. child: Text(
  203. label,
  204. style: TextStyle(
  205. fontSize: 14,
  206. fontWeight: FontWeight.w600,
  207. color: selected ? Colors.white : ScribeColors.primaryText,
  208. ),
  209. ),
  210. ),
  211. ),
  212. );
  213. }
  214. }
  215. /// Sentence-case metadata on a quiet neutral fill, with wrapping.
  216. class NoteFact extends StatelessWidget {
  217. const NoteFact({super.key, required this.text});
  218. final String text;
  219. @override
  220. Widget build(BuildContext context) {
  221. return Container(
  222. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
  223. decoration: BoxDecoration(
  224. color: ScribeColors.canvas,
  225. borderRadius: BorderRadius.circular(8),
  226. ),
  227. child: Text(text, style: ScribeType.metadata),
  228. );
  229. }
  230. }
  231. /// An icon and explanation for information or errors.
  232. class InlineNotice extends StatelessWidget {
  233. const InlineNotice({
  234. super.key,
  235. required this.message,
  236. this.isError = false,
  237. this.onRetry,
  238. });
  239. final String message;
  240. final bool isError;
  241. final VoidCallback? onRetry;
  242. @override
  243. Widget build(BuildContext context) {
  244. return Container(
  245. width: double.infinity,
  246. padding: const EdgeInsets.all(ScribeSpacing.panelPadding),
  247. decoration: BoxDecoration(
  248. color: isError ? ScribeColors.warningSurface : ScribeColors.infoSurface,
  249. borderRadius: BorderRadius.circular(ScribeSpacing.controlRadius),
  250. ),
  251. child: Row(
  252. crossAxisAlignment: CrossAxisAlignment.start,
  253. children: [
  254. Icon(
  255. isError ? CupertinoIcons.exclamationmark_triangle : CupertinoIcons.info,
  256. size: 20,
  257. color: isError ? ScribeColors.danger : ScribeColors.accentText,
  258. ),
  259. const SizedBox(width: 10),
  260. Expanded(
  261. child: Text(message, style: ScribeType.body),
  262. ),
  263. if (onRetry != null)
  264. TextButton(onPressed: onRetry, child: const Text('Retry')),
  265. ],
  266. ),
  267. );
  268. }
  269. }
  270. /// A familiar glyph in a tinted 40-point tile.
  271. class CategoryMark extends StatelessWidget {
  272. const CategoryMark({
  273. super.key,
  274. required this.icon,
  275. this.tint = ScribeColors.accent,
  276. this.soft = ScribeColors.accentSoft,
  277. });
  278. final IconData icon;
  279. final Color tint;
  280. final Color soft;
  281. @override
  282. Widget build(BuildContext context) {
  283. return Container(
  284. width: 40,
  285. height: 40,
  286. decoration: BoxDecoration(
  287. color: soft,
  288. borderRadius: BorderRadius.circular(10),
  289. ),
  290. alignment: Alignment.center,
  291. child: Icon(icon, size: 20, color: tint),
  292. );
  293. }
  294. }
  295. /// Readable sentence-case status with a dot.
  296. class StatusTag extends StatelessWidget {
  297. const StatusTag({
  298. super.key,
  299. required this.label,
  300. required this.color,
  301. });
  302. final String label;
  303. final Color color;
  304. @override
  305. Widget build(BuildContext context) {
  306. return Row(
  307. mainAxisSize: MainAxisSize.min,
  308. children: [
  309. Container(
  310. width: 8,
  311. height: 8,
  312. decoration: BoxDecoration(color: color, shape: BoxShape.circle),
  313. ),
  314. const SizedBox(width: 6),
  315. Text(label, style: ScribeType.metadata),
  316. ],
  317. );
  318. }
  319. }
  320. /// Restrained section hierarchy text.
  321. class SectionLabel extends StatelessWidget {
  322. const SectionLabel(this.text, {super.key});
  323. final String text;
  324. @override
  325. Widget build(BuildContext context) {
  326. return Text(text.toUpperCase(),
  327. style: ScribeType.sectionLabel.copyWith(letterSpacing: 0.5));
  328. }
  329. }
  330. /// App wordmark.
  331. class Wordmark extends StatelessWidget {
  332. const Wordmark({super.key});
  333. @override
  334. Widget build(BuildContext context) {
  335. return const Text('RackPeek', style: ScribeType.wordmark);
  336. }
  337. }
  338. /// Cupertino activity indicator.
  339. class ScribeSpinner extends StatelessWidget {
  340. const ScribeSpinner({super.key});
  341. @override
  342. Widget build(BuildContext context) {
  343. return const Center(
  344. child: Padding(
  345. padding: EdgeInsets.all(ScribeSpacing.majorSectionGap),
  346. child: CupertinoActivityIndicator(radius: 14),
  347. ),
  348. );
  349. }
  350. }
  351. /// Scrollable, safe-area-aware column with screen margins.
  352. class ScribeSheet extends StatelessWidget {
  353. const ScribeSheet({
  354. super.key,
  355. required this.children,
  356. this.scrollable = true,
  357. this.horizontalPadding = ScribeSpacing.screenMargin,
  358. this.sectionGap = ScribeSpacing.majorSectionGap,
  359. });
  360. final List<Widget> children;
  361. final bool scrollable;
  362. final double horizontalPadding;
  363. final double sectionGap;
  364. @override
  365. Widget build(BuildContext context) {
  366. final Column content = Column(
  367. crossAxisAlignment: CrossAxisAlignment.stretch,
  368. children: _spaced(children, sectionGap),
  369. );
  370. if (!scrollable) {
  371. return SafeArea(
  372. child: Padding(
  373. padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
  374. child: content,
  375. ),
  376. );
  377. }
  378. return SafeArea(
  379. child: SingleChildScrollView(
  380. padding: EdgeInsets.symmetric(
  381. horizontal: horizontalPadding, vertical: 8),
  382. child: Column(
  383. crossAxisAlignment: CrossAxisAlignment.stretch,
  384. children: _spaced(children, sectionGap),
  385. ),
  386. ),
  387. );
  388. }
  389. static List<Widget> _spaced(List<Widget> children, double sectionGap) {
  390. final List<Widget> result = [];
  391. for (var i = 0; i < children.length; i++) {
  392. result.add(children[i]);
  393. if (i < children.length - 1) {
  394. result.add(SizedBox(height: sectionGap));
  395. }
  396. }
  397. return result;
  398. }
  399. }