zero_state 1.0.0
zero_state: ^1.0.0 copied to clipboard
Next-generation Flutter state management with 120Hz Element-Bypass rendering, speculative intent prefetching, background isolate graphs, A2UI, and LWW-CRDT.
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:zero_state/zero_state.dart';
import 'arena_crdt_war_view.dart';
import 'arena_dict.dart';
import 'arena_speculative_view.dart';
import 'arena_ticker_view.dart';
import 'showcase_controller.dart';
import 'showcase_dict.dart';
import 'showcase_painters.dart';
import 'showcase_sections.dart';
export 'showcase_controller.dart' show ShowcaseWaveState;
void main() => runApp(const ZeroShowcaseApp());
/// Showcase application presenting 4 independent torture arenas (Multi-Arena
/// Torture Suite) for the Zero State Management Engine with zero parent widget rebuilds.
class ZeroShowcaseApp extends StatefulWidget {
const ZeroShowcaseApp({this.initialShader, super.key});
final ui.FragmentShader? initialShader;
@override
State<ZeroShowcaseApp> createState() => _ZeroShowcaseAppState();
}
class _ZeroShowcaseAppState extends State<ZeroShowcaseApp> {
late final ShowcaseStressController _ctrl;
late final ZeroCell<int> _activeArenaCell;
int _parentBuildCount = 0;
@override
void initState() {
super.initState();
_activeArenaCell = ZeroCell<int>(0);
_ctrl = ShowcaseStressController(
initialShader: widget.initialShader,
onClassicSetStateTrigger: () {
if (mounted) setState(() {});
},
);
}
@override
void dispose() {
_activeArenaCell.dispose();
_ctrl.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
_parentBuildCount++;
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: const Color(0xFF0B0F19),
appBar: AppBar(
backgroundColor: const Color(0xFF141B2D),
title: Text(
ShowcaseDict.appBarTitle(_parentBuildCount),
style: const TextStyle(color: Colors.white, fontSize: 15),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(42),
child: _buildArenaSelectorBar(),
),
),
body: ValueListenableBuilder<int>(
valueListenable: _activeArenaCell,
builder: (_, arenaIndex, __) => switch (arenaIndex) {
0 => _buildArena1GpuIsolateBody(),
1 => const ArenaTickerView(),
2 => const ArenaSpeculativeView(),
_ => const ArenaCrdtWarView(),
},
),
),
);
}
Widget _buildArenaSelectorBar() {
const tabs = <String>[
ArenaDict.tab1GpuIsolate,
ArenaDict.tab2CryptoGrid,
ArenaDict.tab3Speculative,
ArenaDict.tab4CrdtWar,
];
return ValueListenableBuilder<int>(
valueListenable: _activeArenaCell,
builder: (_, activeIdx, __) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: Row(
children: List<Widget>.generate(tabs.length, (i) {
final isSelected = activeIdx == i;
return Padding(
padding: const EdgeInsets.only(right: 4),
child: ChoiceChip(
key: Key('tab_arena_$i'),
visualDensity: VisualDensity.compact,
labelPadding: const EdgeInsets.symmetric(horizontal: 4),
label: Text(
tabs[i],
style: TextStyle(
color: isSelected ? Colors.black : Colors.white,
fontWeight: FontWeight.bold,
fontSize: 11.0,
),
),
selected: isSelected,
selectedColor: const Color(0xFF00E5FF),
backgroundColor: const Color(0xFF1E2942),
onSelected: (_) => _activeArenaCell.value = i,
),
);
}),
),
),
);
}
Widget _buildArena1GpuIsolateBody() => SingleChildScrollView(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ShowcaseStressControlBanner(
isStressRunningCell: _ctrl.isStressRunningCell,
isClassicModeCell: _ctrl.isClassicModeCell,
motionCell: _ctrl.signalAmplitudeCell,
onToggleStress: _ctrl.toggleStressLoop,
onToggleClassicMode: _ctrl.toggleClassicMode,
),
const SizedBox(height: 14),
_buildSectionTitle(ShowcaseDict.section1Title),
_buildShaderSection(),
SizedBox(
height: 64,
child: ZeroPaintSurface<double>(
cell: _ctrl.signalAmplitudeCell,
semanticsBuilder: ShowcaseDict.amplitudeSemantics,
painter: ShowcasePainters.paintAmplitudeBar,
),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _ctrl.stepHighFrequencySignal,
child: const Text(ShowcaseDict.stepSignalButton),
),
const SizedBox(height: 14),
_buildSectionTitle(ShowcaseDict.section3Title),
ShowcaseGenericIsolateSection(
isolateGraph: _ctrl.genericIsolateGraph,
onDispatchKernel: _ctrl.dispatchGenericKernel,
),
const SizedBox(height: 14),
_buildSectionTitle(ShowcaseDict.section4Title),
ShowcaseA2UiTelemetrySection(
decisionGraph: _ctrl.decisionGraph,
onInjectJank: _ctrl.injectSimulatedFrameTimingJank,
),
const SizedBox(height: 14),
_buildSectionTitle(ShowcaseDict.section5Title),
ValueListenableBuilder<String?>(
valueListenable: _ctrl.hotCrdtKeyCell,
builder: (_, hotVal, __) => ShowcaseInfoBox(
text: ShowcaseDict.crdtStressStatus(
totalActiveKeys: _ctrl.crdtStore.activeCount,
materializations:
_ctrl.crdtStore.snapshotCell.materializationCount,
hotKeyValue: hotVal ?? '-',
surgicalAlertEpoch: _ctrl.surgicalStressBandCell.epoch,
classicMapCopies: _ctrl.classicMapCopyCount,
),
),
),
const SizedBox(height: 14),
_buildSectionTitle(ShowcaseDict.section2Title),
ShowcaseSpeculativeSection(
intentTracker: _ctrl.intentTracker,
shadowCache: _ctrl.shadowCache,
decisionGraph: _ctrl.decisionGraph,
),
],
),
);
Widget _buildShaderSection() => ValueListenableBuilder<ui.FragmentShader?>(
valueListenable: _ctrl.loadedShaderCell,
builder: (_, shader, __) => shader == null
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.only(bottom: 8),
child: SizedBox(
height: 96,
child: ZeroShaderSurface<ShowcaseWaveState>(
cell: _ctrl.waveShaderCell,
shader: shader,
uniformCount: 7,
packer: (s, b) {
b[2] = s.time;
b[3] = s.freq;
b[4] = s.amp;
b[5] = s.time * 0.8;
b[6] = s.stress;
},
),
),
),
);
Widget _buildSectionTitle(String title) => Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Text(
title,
style: const TextStyle(color: Colors.white70, fontWeight: FontWeight.bold),
),
);
}