gloss_ui 0.1.0
gloss_ui: ^0.1.0 copied to clipboard
Skeuomorphic Flutter widgets of glazed, moulded parts under one light: jade gel for the main action, pearl for what you handle, wells pressed into porcelain.
// Simmer, a week of dinners set in Gloss: the look's Overview, then Today, Recipes, the shopping List and Settings,
// moved between by the look's own navigation (the bottom bar on a phone, the rail from 600, the sidebar from 1024).
// The Overview ends in the index of every part's page. A link opens it as the looks' galleries share:
// `/#/<page>?theme=dark&dir=rtl&text=200`, where the page is a part's page by its id (`buttons`, `fields`,
// `choices`...) or a screen by its name (`overview`, `home`, `recipes`, `shopping`, `settings`), or a scene of one
// (`/#/scene/recipe`, `filter`, `planner`, `deletePlan`, `search`, `searchNone`, `syncFailed`, `emptyList`);
// `theme=dark` at night, `dir=rtl` right to left, `text=200` the words at twice the size, `density=comfortable|compact`
// that density. `?slow=8` runs every animation eight times slower; `?a11y=1` turns the semantics on from the start;
// `?keylines=1` draws ui_core's keyline sheet over it.
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:flutter/widgets.dart';
import 'package:gloss_ui/gloss_ui.dart';
import 'package:ui_core_test/ui_core_test.dart';
import 'gallery_pages.dart';
import 'kit_gallery/simmer/simmer.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// The face before the first frame: on the web the words never flash in a fallback face.
await glossLoadFonts();
final hash = Uri.base.fragment.startsWith('/')
? Uri.parse(Uri.base.fragment)
: null;
final query = {...Uri.base.queryParameters, ...?hash?.queryParameters};
final segments =
hash?.pathSegments.where((s) => s.isNotEmpty).toList() ??
const <String>[];
final (place, scene, part) = switch (segments) {
['scene', final name, ...] => (
null,
SimmerScene.values.where((s) => s.name == name).firstOrNull,
null,
),
[final id, ...] when galleryPages.any((p) => p.id == id) => (
null,
null,
id,
),
[final name, ...] => (
SimmerPlace.values.where((p) => p.name == name).firstOrNull,
null,
null,
),
_ => (null, null, null),
};
final text = double.tryParse(query['text'] ?? '');
timeDilation = double.tryParse(query['slow'] ?? '') ?? 1;
if (query['a11y'] == '1') WidgetsBinding.instance.ensureSemantics();
final app = SimmerApp(
initialPlace:
place ??
switch (scene) {
null => SimmerPlace.overview,
final scene => scene.place,
},
initialScene: scene,
initialAppearance: query['theme'] == 'dark'
? SimmerAppearance.dark
: SimmerAppearance.light,
initialDirection: query['dir'] == 'rtl'
? TextDirection.rtl
: TextDirection.ltr,
initialDensity: switch (query['density']) {
'comfortable' => GlossDensity.comfortable,
'compact' => GlossDensity.compact,
_ => null,
},
// `text=200` is a percentage, `text=2` a factor.
textScale: text == null ? null : (text > 5 ? text / 100 : text),
parts: [
for (final page in galleryPages) (title: page.title, build: page.build),
],
initialPart: switch (galleryPages.indexWhere((p) => p.id == part)) {
-1 => null,
final i => i,
},
);
runApp(
query['keylines'] == '1'
? Directionality(
textDirection: TextDirection.ltr,
child: DesignKeylineSheet(
check: const DesignKeylineCheck(look: 'Gloss'),
child: app,
),
)
: app,
);
}