Compare commits
22 Commits
f19578cfc4
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
660cc17f56 | ||
|
|
5feda3a909 | ||
|
|
45b40d9bbd | ||
|
|
739de72051 | ||
|
|
1fa8207b01 | ||
|
|
c60f045967 | ||
|
|
140ba9374e | ||
|
|
8dcfa57122 | ||
|
|
22b06b800a | ||
|
|
d7ec54d8ca | ||
|
|
31981fb19e | ||
|
|
f2e7a05e54 | ||
|
|
33e372b330 | ||
|
|
fa8529fca0 | ||
|
|
d4fe94b8b9 | ||
|
|
5c91f5a928 | ||
|
|
bfcd9fe606 | ||
|
|
1352fd5513 | ||
|
|
85f06c3785 | ||
|
|
d08174c79f | ||
|
|
e493faaf27 | ||
|
|
80a4a1126b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -29,3 +29,4 @@ migrate_working_dir/
|
||||
.flutter-plugins-dependencies
|
||||
/build/
|
||||
/coverage/
|
||||
example/build
|
||||
|
||||
25
.vscode/launch.json
vendored
Normal file
25
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "markettakers-flutter",
|
||||
"request": "launch",
|
||||
"type": "dart"
|
||||
},
|
||||
{
|
||||
"name": "markettakers-flutter (profile mode)",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "profile"
|
||||
},
|
||||
{
|
||||
"name": "markettakers-flutter (release mode)",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "release"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:markettakers/main.dart';
|
||||
|
||||
class SimpleStage extends StageFactory {
|
||||
@override
|
||||
final String title = "Test";
|
||||
|
||||
@override
|
||||
Future<bool> get isCompleted async {
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> start(StageController controller) async {
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.3);
|
||||
controller.updateTitle("test 2");
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.6);
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleStage2 extends StageFactory {
|
||||
@override
|
||||
final String title = "Test 2";
|
||||
|
||||
@override
|
||||
Future<bool> get isCompleted async {
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> start(StageController controller) async {
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.3);
|
||||
controller.updateTitle("test 5");
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.6);
|
||||
}
|
||||
}
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
init();
|
||||
final completer = Completer<void>();
|
||||
completer.future.then((_) {
|
||||
talker.info("Bootstrapper completed, launching app");
|
||||
});
|
||||
runApp(
|
||||
Scaffold(
|
||||
body: Bootstrapper(
|
||||
stages: [SimpleStage(), SimpleStage2()],
|
||||
onCompleted: completer,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rive_native/rive_native.dart';
|
||||
import 'package:talker_flutter/talker_flutter.dart';
|
||||
|
||||
export 'package:markettakers/src/bootstrapper.dart'
|
||||
show Bootstrapper, StageFactory, StageController;
|
||||
|
||||
final talker = Talker();
|
||||
|
||||
final commonTheme = ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.deepPurple,
|
||||
brightness: Brightness.dark,
|
||||
).copyWith(secondary: Colors.deepPurpleAccent),
|
||||
);
|
||||
|
||||
void init() async {
|
||||
await RiveNative.init();
|
||||
}
|
||||
@@ -1,59 +1,22 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:markettakers/main.dart';
|
||||
import 'package:talker_flutter/talker_flutter.dart';
|
||||
|
||||
class SimpleStage extends StageFactory {
|
||||
final String title = "Test";
|
||||
export 'package:mtcore/src/bootstrapper.dart'
|
||||
show Bootstrapper, StageFactory, StageController;
|
||||
|
||||
@override
|
||||
Future<bool> get isCompleted async {
|
||||
return false;
|
||||
}
|
||||
export 'package:mtcore/src/about_screen.dart' show AboutScreen;
|
||||
export 'package:mtcore/src/loader.dart'
|
||||
show Loader, LoaderFlavour, LoaderController;
|
||||
export 'package:mtcore/src/credits.dart' show Credits;
|
||||
|
||||
@override
|
||||
Future<void> start(StageController controller) async {
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.3);
|
||||
controller.updateTitle("test 2");
|
||||
final talker = Talker();
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.6);
|
||||
}
|
||||
}
|
||||
final ThemeData commonTheme = ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.deepPurple,
|
||||
brightness: Brightness.dark,
|
||||
secondary: Colors.deepPurpleAccent,
|
||||
),
|
||||
);
|
||||
|
||||
class SimpleStage2 extends StageFactory {
|
||||
final String title = "Test 2";
|
||||
|
||||
@override
|
||||
Future<bool> get isCompleted async {
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> start(StageController controller) async {
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.3);
|
||||
controller.updateTitle("test 5");
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
controller.updateProgress(0.6);
|
||||
}
|
||||
}
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
init();
|
||||
final completer = Completer<void>();
|
||||
completer.future.then((_) {
|
||||
talker.info("Bootstrapper completed, launching app");
|
||||
});
|
||||
runApp(
|
||||
Scaffold(
|
||||
body: Bootstrapper(
|
||||
stages: [SimpleStage(), SimpleStage2()],
|
||||
onCompleted: completer,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Future<void> init() async {}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:markettakers/main.dart';
|
||||
import 'package:markettakers/src/loaders/loader.dart';
|
||||
import 'package:mtcore/markettakers.dart';
|
||||
import 'package:talker_flutter/talker_flutter.dart';
|
||||
|
||||
class AboutScreen extends StatelessWidget {
|
||||
@@ -18,10 +17,7 @@ class AboutScreen extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: Loader(flavour: LoaderFlavour.big, playing: true),
|
||||
),
|
||||
Flexible(flex: 2, child: Loader.playing(flavour: LoaderFlavour.big)),
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: Text(
|
||||
@@ -42,7 +38,7 @@ class AboutScreen extends StatelessWidget {
|
||||
Credits(),
|
||||
|
||||
Footer(children: children),
|
||||
const Text("MarketTakers (c) 2025"),
|
||||
const Text("MarketTakers (c) 2026"),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -57,41 +53,23 @@ class Footer extends StatelessWidget {
|
||||
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FractionallySizedBox(
|
||||
widthFactor: 0.5,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TalkerScreen(talker: talker),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text("View Logs"),
|
||||
),
|
||||
...children,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Credits extends StatelessWidget {
|
||||
const Credits({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Made with "),
|
||||
const Icon(Icons.favorite, color: Colors.red),
|
||||
const Text(" by Skipper, Clewerwild and karabyn2187"),
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TalkerScreen(talker: talker),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text("View Logs"),
|
||||
),
|
||||
...children,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,154 +1,313 @@
|
||||
import 'dart:async';
|
||||
import 'dart:isolate';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:markettakers/main.dart';
|
||||
import 'package:markettakers/src/loaders/loader.dart';
|
||||
// ignore_for_file: annotate_overrides
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:mtcore/markettakers.dart';
|
||||
import 'package:percent_indicator/circular_percent_indicator.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'bootstrapper.g.dart';
|
||||
part 'bootstrapper.freezed.dart';
|
||||
|
||||
/// A single bootstrap stage.
|
||||
/// Implementations should report progress/title updates via [StageController].
|
||||
abstract class StageFactory {
|
||||
String get title;
|
||||
|
||||
Future<bool> get isCompleted async => false;
|
||||
/// Optional: if your stage can be skipped when already completed.
|
||||
Future<bool> get isAlreadyCompleted async => false;
|
||||
|
||||
Future<void> start(StageController controller);
|
||||
|
||||
void dispose() {}
|
||||
}
|
||||
|
||||
/// Bootstrap progress: either definite (0..1) or indefinite.
|
||||
@freezed
|
||||
sealed class Progress with _$Progress {
|
||||
const factory Progress.definite(double value) = PercentageProgress;
|
||||
const factory Progress.indefinite() = IndefiniteProgress;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class StageState with _$StageState {
|
||||
final String title;
|
||||
final double progress;
|
||||
String title;
|
||||
Progress progress;
|
||||
|
||||
StageState({required this.title, required this.progress});
|
||||
}
|
||||
|
||||
class StageController extends Cubit<StageState> {
|
||||
StageController({required String title})
|
||||
: super(StageState(title: title, progress: 0.0));
|
||||
typedef Stages = List<StageFactory>;
|
||||
|
||||
void updateProgress(double progress) {
|
||||
emit(state.copyWith(progress: progress));
|
||||
@riverpod
|
||||
class CurrentStage extends _$CurrentStage {
|
||||
@override
|
||||
StageState? build() => null;
|
||||
|
||||
void set(StageState newState) => state = newState;
|
||||
|
||||
void setProgress(Progress progress) {
|
||||
final s = state;
|
||||
if (s == null) return;
|
||||
state = s.copyWith(progress: progress);
|
||||
}
|
||||
|
||||
void setTitle(String title) {
|
||||
final s = state;
|
||||
if (s == null) return;
|
||||
state = s.copyWith(title: title);
|
||||
}
|
||||
}
|
||||
|
||||
class StageController {
|
||||
final Ref _ref;
|
||||
StageController(this._ref);
|
||||
|
||||
void setDefiniteProgress(double value) {
|
||||
if (!_ref.mounted) return;
|
||||
_ref
|
||||
.read(currentStageProvider.notifier)
|
||||
.setProgress(Progress.definite(value));
|
||||
}
|
||||
|
||||
void setIndefiniteProgress() {
|
||||
if (!_ref.mounted) return;
|
||||
_ref
|
||||
.read(currentStageProvider.notifier)
|
||||
.setProgress(const Progress.indefinite());
|
||||
}
|
||||
|
||||
void updateTitle(String title) {
|
||||
emit(state.copyWith(title: title));
|
||||
if (!_ref.mounted) return;
|
||||
_ref.read(currentStageProvider.notifier).setTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
typedef Stages = List<StageFactory>;
|
||||
@riverpod
|
||||
class StagesWorker extends _$StagesWorker {
|
||||
bool _hasStarted = false;
|
||||
|
||||
@freezed
|
||||
class BootstrapState with _$BootstrapState {
|
||||
final Stages stages;
|
||||
final int currentStageIndex;
|
||||
final StageController? controller;
|
||||
@override
|
||||
Future<bool> build() async => false;
|
||||
|
||||
StageFactory get currentStage => stages[currentStageIndex];
|
||||
bool get isCompleted => currentStageIndex > stages.length;
|
||||
Future<void> start(Stages stages) async {
|
||||
if (_hasStarted) return;
|
||||
_hasStarted = true;
|
||||
|
||||
BootstrapState(this.stages, {this.currentStageIndex = 0, this.controller});
|
||||
}
|
||||
state = const AsyncValue.loading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
for (final stage in stages) {
|
||||
talker.info("${stage.title} starting");
|
||||
|
||||
@freezed
|
||||
sealed class BootstrapEvent with _$BootstrapEvent {
|
||||
const factory BootstrapEvent.start() = StartEvent;
|
||||
const factory BootstrapEvent.stageCompleted() = StageCompletedEvent;
|
||||
const factory BootstrapEvent.finished() = FinishedEvent;
|
||||
}
|
||||
// Optional skip.
|
||||
final alreadyDone = await stage.isAlreadyCompleted;
|
||||
if (alreadyDone) {
|
||||
talker.info("${stage.title} skipped (already completed)");
|
||||
continue;
|
||||
}
|
||||
|
||||
class BootstrapController extends Bloc<BootstrapEvent, BootstrapState> {
|
||||
BootstrapController(super.initialState) {
|
||||
assert(state.stages.isNotEmpty, "Stages list cannot be empty");
|
||||
ref
|
||||
.read(currentStageProvider.notifier)
|
||||
.set(
|
||||
StageState(
|
||||
title: stage.title,
|
||||
progress: const Progress.indefinite(),
|
||||
),
|
||||
);
|
||||
|
||||
on<StartEvent>((event, emit) {
|
||||
talker.info("BootstrapController: Starting bootstrap process");
|
||||
final controller = launchCurrentStage(
|
||||
state.stages,
|
||||
state.currentStageIndex,
|
||||
);
|
||||
emit(state.copyWith(controller: controller));
|
||||
});
|
||||
on<StageCompletedEvent>((event, emit) async {
|
||||
talker.info("BootstrapController: ${state.currentStage.title} completed");
|
||||
state.currentStage.dispose();
|
||||
|
||||
final nextIndex = state.currentStageIndex + 1;
|
||||
final newState = state.copyWith(currentStageIndex: nextIndex);
|
||||
|
||||
if (newState.isCompleted) {
|
||||
talker.info("BootstrapController: All stages completed");
|
||||
} else if (await newState.currentStage.isCompleted) {
|
||||
talker.info(
|
||||
"BootstrapController: Stage ${newState.currentStage.title} already completed, skipping",
|
||||
);
|
||||
add(const BootstrapEvent.stageCompleted());
|
||||
} else {
|
||||
final nextStage = newState.currentStage;
|
||||
talker.info("BootstrapController: Starting stage ${nextStage.title}");
|
||||
launchCurrentStage(state.stages, nextIndex);
|
||||
emit(newState);
|
||||
await stage.start(StageController(ref));
|
||||
talker.info("${stage.title} completed");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
StageController launchCurrentStage(Stages stages, int index) {
|
||||
final currentStage = stages[index];
|
||||
final controller = StageController(title: currentStage.title);
|
||||
|
||||
Isolate.run(
|
||||
() => currentStage
|
||||
.start(controller)
|
||||
.then((_) {
|
||||
talker.info(
|
||||
"BootstrapController: Stage ${currentStage.title} completed",
|
||||
);
|
||||
add(BootstrapEvent.stageCompleted());
|
||||
})
|
||||
.catchError((error) {
|
||||
talker.handle(
|
||||
error,
|
||||
null,
|
||||
"BootstrapController: Error in ${currentStage.title}",
|
||||
);
|
||||
addError(error);
|
||||
}),
|
||||
);
|
||||
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
|
||||
class BootstrapFooter extends StatelessWidget {
|
||||
const BootstrapFooter({super.key});
|
||||
class _DefiniteIndicator extends StatelessWidget {
|
||||
final double progress; // 0.0 to 1.0
|
||||
const _DefiniteIndicator({required this.progress});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<BootstrapController, BootstrapState>(
|
||||
builder: (context, state) {
|
||||
final controller = state.controller;
|
||||
if (controller == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
"${state.currentStage.title} ${controller.state.progress.toStringAsFixed(2)}%",
|
||||
// Make it adaptive and square to prevent overflow in flexible layouts.
|
||||
return AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final side = c.maxWidth.isFinite ? c.maxWidth : 120.0;
|
||||
final radius = side * 0.42; // padding around ring
|
||||
final stroke = (side * 0.08).clamp(4.0, 10.0);
|
||||
|
||||
final value = progress.clamp(0.0, 1.0);
|
||||
final formattedProgress = "${(value * 100).toStringAsFixed(0)}%";
|
||||
|
||||
return Center(
|
||||
child: CircularPercentIndicator(
|
||||
radius: radius,
|
||||
lineWidth: stroke,
|
||||
percent: value,
|
||||
center: Text(
|
||||
formattedProgress,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
circularStrokeCap: CircularStrokeCap.round,
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withValues(alpha: 0.12),
|
||||
progressColor: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
CircularProgressIndicator.adaptive(
|
||||
value: controller.state.progress,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Bootstrapper extends StatelessWidget {
|
||||
class _IndefiniteIndicator extends StatelessWidget {
|
||||
const _IndefiniteIndicator();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final side = c.maxWidth.isFinite ? c.maxWidth : 120.0;
|
||||
final size = side * 0.55;
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: SpinKitRing(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
lineWidth: (side * 0.06).clamp(3.0, 8.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FrostCard extends StatelessWidget {
|
||||
const _FrostCard({required this.child});
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 14, sigmaY: 14),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface.withValues(alpha: 0.10),
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
border: Border.all(
|
||||
color: cs.onSurface.withValues(alpha: 0.10),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BackgroundGlow extends StatelessWidget {
|
||||
const _BackgroundGlow();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
gradient: RadialGradient(
|
||||
center: const Alignment(0, -0.55),
|
||||
radius: 1.25,
|
||||
colors: [
|
||||
cs.primary.withValues(alpha: 0.18),
|
||||
cs.secondary.withValues(alpha: 0.10),
|
||||
Colors.black,
|
||||
],
|
||||
stops: const [0.0, 0.45, 1.0],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BootstrapFooter extends ConsumerWidget {
|
||||
const _BootstrapFooter();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final stage = ref.watch(currentStageProvider);
|
||||
|
||||
final title = stage?.title ?? "Preparing…";
|
||||
final progress = stage?.progress ?? const Progress.indefinite();
|
||||
|
||||
final indicator = progress.when(
|
||||
definite: (definite) => _DefiniteIndicator(progress: definite),
|
||||
indefinite: () => const _IndefiniteIndicator(),
|
||||
);
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: _FrostCard(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(22),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
child: Text(
|
||||
title,
|
||||
key: ValueKey(title),
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.2,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
"Please don’t close the app",
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withValues(alpha: 0.72),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
SizedBox(height: 180, child: indicator),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Bootstrapper UI + lifecycle glue.
|
||||
///
|
||||
/// - Runs [StagesWorker.start] exactly once (using hooks).
|
||||
/// - Uses `ref.listen` to complete [onCompleted] without rebuilding the logo.
|
||||
/// - Watches only [CurrentStage] for UI updates.
|
||||
class Bootstrapper extends HookConsumerWidget {
|
||||
final Stages stages;
|
||||
final Completer onCompleted;
|
||||
|
||||
@@ -159,34 +318,71 @@ class Bootstrapper extends StatelessWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) {
|
||||
final controller = BootstrapController(BootstrapState(stages));
|
||||
controller.add(const BootstrapEvent.start());
|
||||
controller.launchCurrentStage(stages, 0);
|
||||
return controller;
|
||||
},
|
||||
child: BlocListener<BootstrapController, BootstrapState>(
|
||||
listener: (context, state) {
|
||||
if (state.isCompleted) {
|
||||
onCompleted.complete();
|
||||
}
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
useEffect(() {
|
||||
Future.microtask(
|
||||
() => ref.read(stagesWorkerProvider.notifier).start(stages),
|
||||
);
|
||||
|
||||
return null;
|
||||
}, const []);
|
||||
ref.listen<AsyncValue<bool>>(stagesWorkerProvider, (_, next) {
|
||||
if (onCompleted.isCompleted) return;
|
||||
|
||||
next.whenOrNull(
|
||||
data: (ok) {
|
||||
if (ok) onCompleted.complete();
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 3,
|
||||
child: Center(
|
||||
child: Loader(flavour: LoaderFlavour.big, playing: true),
|
||||
),
|
||||
error: (e, st) => onCompleted.completeError(e, st),
|
||||
);
|
||||
});
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
const _BackgroundGlow(),
|
||||
SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 24),
|
||||
child: Column(
|
||||
children: const [
|
||||
// Keep this as a const child so it doesn't restart animations
|
||||
// when the footer rebuilds.
|
||||
_LogoHeader(),
|
||||
SizedBox(height: 24),
|
||||
Expanded(child: Center(child: _BootstrapFooter())),
|
||||
SizedBox(height: 16),
|
||||
_BottomCaption(),
|
||||
],
|
||||
),
|
||||
Flexible(flex: 1, child: BootstrapFooter()),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LogoHeader extends StatelessWidget {
|
||||
const _LogoHeader();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 160,
|
||||
child: Center(child: Loader.playing(flavour: LoaderFlavour.big)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BottomCaption extends StatelessWidget {
|
||||
const _BottomCaption();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(
|
||||
"Initializing secure components…",
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.55),
|
||||
letterSpacing: 0.2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,268 @@ part of 'bootstrapper.dart';
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$Progress {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is Progress);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Progress()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $ProgressCopyWith<$Res> {
|
||||
$ProgressCopyWith(Progress _, $Res Function(Progress) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [Progress].
|
||||
extension ProgressPatterns on Progress {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>({TResult Function( PercentageProgress value)? definite,TResult Function( IndefiniteProgress value)? indefinite,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case PercentageProgress() when definite != null:
|
||||
return definite(_that);case IndefiniteProgress() when indefinite != null:
|
||||
return indefinite(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>({required TResult Function( PercentageProgress value) definite,required TResult Function( IndefiniteProgress value) indefinite,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case PercentageProgress():
|
||||
return definite(_that);case IndefiniteProgress():
|
||||
return indefinite(_that);}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( PercentageProgress value)? definite,TResult? Function( IndefiniteProgress value)? indefinite,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case PercentageProgress() when definite != null:
|
||||
return definite(_that);case IndefiniteProgress() when indefinite != null:
|
||||
return indefinite(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( double value)? definite,TResult Function()? indefinite,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case PercentageProgress() when definite != null:
|
||||
return definite(_that.value);case IndefiniteProgress() when indefinite != null:
|
||||
return indefinite();case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function( double value) definite,required TResult Function() indefinite,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case PercentageProgress():
|
||||
return definite(_that.value);case IndefiniteProgress():
|
||||
return indefinite();}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function( double value)? definite,TResult? Function()? indefinite,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case PercentageProgress() when definite != null:
|
||||
return definite(_that.value);case IndefiniteProgress() when indefinite != null:
|
||||
return indefinite();case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class PercentageProgress implements Progress {
|
||||
const PercentageProgress(this.value);
|
||||
|
||||
|
||||
final double value;
|
||||
|
||||
/// Create a copy of Progress
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$PercentageProgressCopyWith<PercentageProgress> get copyWith => _$PercentageProgressCopyWithImpl<PercentageProgress>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is PercentageProgress&&(identical(other.value, value) || other.value == value));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,value);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Progress.definite(value: $value)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $PercentageProgressCopyWith<$Res> implements $ProgressCopyWith<$Res> {
|
||||
factory $PercentageProgressCopyWith(PercentageProgress value, $Res Function(PercentageProgress) _then) = _$PercentageProgressCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
double value
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$PercentageProgressCopyWithImpl<$Res>
|
||||
implements $PercentageProgressCopyWith<$Res> {
|
||||
_$PercentageProgressCopyWithImpl(this._self, this._then);
|
||||
|
||||
final PercentageProgress _self;
|
||||
final $Res Function(PercentageProgress) _then;
|
||||
|
||||
/// Create a copy of Progress
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? value = null,}) {
|
||||
return _then(PercentageProgress(
|
||||
null == value ? _self.value : value // ignore: cast_nullable_to_non_nullable
|
||||
as double,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class IndefiniteProgress implements Progress {
|
||||
const IndefiniteProgress();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is IndefiniteProgress);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Progress.indefinite()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$StageState {
|
||||
|
||||
String get title; double get progress;
|
||||
String get title; set title(String value); Progress get progress; set progress(Progress value);
|
||||
/// Create a copy of StageState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@@ -45,7 +303,7 @@ abstract mixin class $StageStateCopyWith<$Res> {
|
||||
factory $StageStateCopyWith(StageState value, $Res Function(StageState) _then) = _$StageStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String title, double progress
|
||||
String title, Progress progress
|
||||
});
|
||||
|
||||
|
||||
@@ -66,7 +324,7 @@ class _$StageStateCopyWithImpl<$Res>
|
||||
return _then(StageState(
|
||||
title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
|
||||
as String,progress: null == progress ? _self.progress : progress // ignore: cast_nullable_to_non_nullable
|
||||
as double,
|
||||
as Progress,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -197,453 +455,4 @@ case _:
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$BootstrapState {
|
||||
|
||||
Stages get stages; int get currentStageIndex; StageController? get controller;
|
||||
/// Create a copy of BootstrapState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$BootstrapStateCopyWith<BootstrapState> get copyWith => _$BootstrapStateCopyWithImpl<BootstrapState>(this as BootstrapState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is BootstrapState&&const DeepCollectionEquality().equals(other.stages, stages)&&(identical(other.currentStageIndex, currentStageIndex) || other.currentStageIndex == currentStageIndex)&&(identical(other.controller, controller) || other.controller == controller));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(stages),currentStageIndex,controller);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BootstrapState(stages: $stages, currentStageIndex: $currentStageIndex, controller: $controller)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $BootstrapStateCopyWith<$Res> {
|
||||
factory $BootstrapStateCopyWith(BootstrapState value, $Res Function(BootstrapState) _then) = _$BootstrapStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<StageFactory> stages, int currentStageIndex, StageController? controller
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$BootstrapStateCopyWithImpl<$Res>
|
||||
implements $BootstrapStateCopyWith<$Res> {
|
||||
_$BootstrapStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final BootstrapState _self;
|
||||
final $Res Function(BootstrapState) _then;
|
||||
|
||||
/// Create a copy of BootstrapState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? stages = null,Object? currentStageIndex = null,Object? controller = freezed,}) {
|
||||
return _then(BootstrapState(
|
||||
null == stages ? _self.stages : stages // ignore: cast_nullable_to_non_nullable
|
||||
as List<StageFactory>,currentStageIndex: null == currentStageIndex ? _self.currentStageIndex : currentStageIndex // ignore: cast_nullable_to_non_nullable
|
||||
as int,controller: freezed == controller ? _self.controller : controller // ignore: cast_nullable_to_non_nullable
|
||||
as StageController?,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [BootstrapState].
|
||||
extension BootstrapStatePatterns on BootstrapState {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>({required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>(){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>() {final _that = this;
|
||||
switch (_that) {
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>() {final _that = this;
|
||||
switch (_that) {
|
||||
case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$BootstrapEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is BootstrapEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BootstrapEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $BootstrapEventCopyWith<$Res> {
|
||||
$BootstrapEventCopyWith(BootstrapEvent _, $Res Function(BootstrapEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [BootstrapEvent].
|
||||
extension BootstrapEventPatterns on BootstrapEvent {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>({TResult Function( StartEvent value)? start,TResult Function( StageCompletedEvent value)? stageCompleted,TResult Function( FinishedEvent value)? finished,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent() when start != null:
|
||||
return start(_that);case StageCompletedEvent() when stageCompleted != null:
|
||||
return stageCompleted(_that);case FinishedEvent() when finished != null:
|
||||
return finished(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>({required TResult Function( StartEvent value) start,required TResult Function( StageCompletedEvent value) stageCompleted,required TResult Function( FinishedEvent value) finished,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent():
|
||||
return start(_that);case StageCompletedEvent():
|
||||
return stageCompleted(_that);case FinishedEvent():
|
||||
return finished(_that);}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( StartEvent value)? start,TResult? Function( StageCompletedEvent value)? stageCompleted,TResult? Function( FinishedEvent value)? finished,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent() when start != null:
|
||||
return start(_that);case StageCompletedEvent() when stageCompleted != null:
|
||||
return stageCompleted(_that);case FinishedEvent() when finished != null:
|
||||
return finished(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? start,TResult Function()? stageCompleted,TResult Function()? finished,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent() when start != null:
|
||||
return start();case StageCompletedEvent() when stageCompleted != null:
|
||||
return stageCompleted();case FinishedEvent() when finished != null:
|
||||
return finished();case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() start,required TResult Function() stageCompleted,required TResult Function() finished,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent():
|
||||
return start();case StageCompletedEvent():
|
||||
return stageCompleted();case FinishedEvent():
|
||||
return finished();}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function()? start,TResult? Function()? stageCompleted,TResult? Function()? finished,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent() when start != null:
|
||||
return start();case StageCompletedEvent() when stageCompleted != null:
|
||||
return stageCompleted();case FinishedEvent() when finished != null:
|
||||
return finished();case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class StartEvent implements BootstrapEvent {
|
||||
const StartEvent();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is StartEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BootstrapEvent.start()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class StageCompletedEvent implements BootstrapEvent {
|
||||
const StageCompletedEvent();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is StageCompletedEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BootstrapEvent.stageCompleted()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class FinishedEvent implements BootstrapEvent {
|
||||
const FinishedEvent();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is FinishedEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BootstrapEvent.finished()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// dart format on
|
||||
|
||||
106
lib/src/bootstrapper.g.dart
Normal file
106
lib/src/bootstrapper.g.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bootstrapper.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(CurrentStage)
|
||||
final currentStageProvider = CurrentStageProvider._();
|
||||
|
||||
final class CurrentStageProvider
|
||||
extends $NotifierProvider<CurrentStage, StageState?> {
|
||||
CurrentStageProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'currentStageProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$currentStageHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
CurrentStage create() => CurrentStage();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(StageState? value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<StageState?>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$currentStageHash() => r'7da6320c5c830e9438bf752dc990297dd410d25a';
|
||||
|
||||
abstract class _$CurrentStage extends $Notifier<StageState?> {
|
||||
StageState? build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<StageState?, StageState?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<StageState?, StageState?>,
|
||||
StageState?,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
|
||||
@ProviderFor(StagesWorker)
|
||||
final stagesWorkerProvider = StagesWorkerProvider._();
|
||||
|
||||
final class StagesWorkerProvider
|
||||
extends $AsyncNotifierProvider<StagesWorker, bool> {
|
||||
StagesWorkerProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'stagesWorkerProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$stagesWorkerHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
StagesWorker create() => StagesWorker();
|
||||
}
|
||||
|
||||
String _$stagesWorkerHash() => r'44d8ae0ea8910ee05343c96e4056226e293afd67';
|
||||
|
||||
abstract class _$StagesWorker extends $AsyncNotifier<bool> {
|
||||
FutureOr<bool> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<AsyncValue<bool>, bool>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<bool>, bool>,
|
||||
AsyncValue<bool>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
17
lib/src/credits.dart
Normal file
17
lib/src/credits.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Credits extends StatelessWidget {
|
||||
const Credits({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Made with "),
|
||||
const Icon(Icons.favorite, color: Colors.red),
|
||||
const Text(" by MT.Dev team"),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
77
lib/src/loader.dart
Normal file
77
lib/src/loader.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
|
||||
enum LoaderFlavour {
|
||||
small(filepath: 'assets/animations/loaders/small_loader.riv'),
|
||||
big(filepath: 'assets/animations/big_loaders/big_logo_splash.riv');
|
||||
|
||||
const LoaderFlavour({required this.filepath});
|
||||
|
||||
final String filepath;
|
||||
}
|
||||
|
||||
class LoaderController extends Cubit<bool> {
|
||||
LoaderController() : super(false);
|
||||
|
||||
void show() => emit(true);
|
||||
void hide() => emit(false);
|
||||
}
|
||||
|
||||
class Loader extends HookWidget {
|
||||
final LoaderFlavour flavour;
|
||||
final Fit fit;
|
||||
final LoaderController controller;
|
||||
|
||||
const Loader(
|
||||
this.controller, {
|
||||
super.key,
|
||||
required this.flavour,
|
||||
this.fit = Fit.contain,
|
||||
});
|
||||
|
||||
Loader.playing({required LoaderFlavour flavour, Fit fit = Fit.contain})
|
||||
: this(LoaderController()..show(), flavour: flavour, fit: fit);
|
||||
Loader.stopped({required LoaderFlavour flavour, Fit fit = Fit.contain})
|
||||
: this(LoaderController()..hide(), flavour: flavour, fit: fit);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
final animFile = useMemoized(
|
||||
() =>
|
||||
FileLoader.fromAsset("packages/mtcore/${flavour.filepath}", riveFactory: Factory.flutter),
|
||||
);
|
||||
|
||||
return RiveWidgetBuilder(
|
||||
fileLoader: animFile,
|
||||
builder: (context, state) {
|
||||
switch (state) {
|
||||
case RiveLoading():
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
||||
case RiveFailed():
|
||||
final message = state.error.toString();
|
||||
return ErrorWidget.withDetails(
|
||||
message: message,
|
||||
error: FlutterError(message),
|
||||
);
|
||||
|
||||
case RiveLoaded(:final file):
|
||||
final controller = RiveWidgetController(
|
||||
file,
|
||||
stateMachineSelector: StateMachineSelector.byIndex(0),
|
||||
);
|
||||
controller.active = this.controller.state;
|
||||
|
||||
this.controller.stream.listen((toggle) {
|
||||
controller.active = toggle;
|
||||
});
|
||||
|
||||
return RiveWidget(controller: controller, fit: fit);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'base_loader.g.dart';
|
||||
|
||||
@riverpod
|
||||
class LoaderState extends _$LoaderState {
|
||||
@override
|
||||
bool build() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
state = false;
|
||||
}
|
||||
|
||||
void start() {
|
||||
state = true;
|
||||
}
|
||||
}
|
||||
|
||||
class BaseLoader extends HookConsumerWidget {
|
||||
final String filepath;
|
||||
final Fit fit;
|
||||
|
||||
const BaseLoader({super.key, required this.filepath, this.fit = Fit.contain});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final loaderState = ref.watch(loaderStateProvider);
|
||||
final animFile = useMemoized(
|
||||
() => FileLoader.fromAsset(filepath, riveFactory: Factory.flutter),
|
||||
);
|
||||
|
||||
useEffect(() {
|
||||
return animFile.dispose;
|
||||
}, [animFile]);
|
||||
|
||||
return RiveWidgetBuilder(
|
||||
fileLoader: animFile,
|
||||
builder: (context, state) {
|
||||
switch (state) {
|
||||
case RiveLoading():
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
||||
case RiveFailed():
|
||||
final message = state.error.toString();
|
||||
return ErrorWidget.withDetails(
|
||||
message: message,
|
||||
error: FlutterError(message),
|
||||
);
|
||||
|
||||
case RiveLoaded(:final file):
|
||||
final controller = RiveWidgetController(
|
||||
file,
|
||||
stateMachineSelector: StateMachineSelector.byIndex(0),
|
||||
);
|
||||
controller.active = loaderState;
|
||||
return RiveWidget(controller: controller, fit: fit);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'base_loader.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(LoaderState)
|
||||
const loaderStateProvider = LoaderStateProvider._();
|
||||
|
||||
final class LoaderStateProvider extends $NotifierProvider<LoaderState, bool> {
|
||||
const LoaderStateProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'loaderStateProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$loaderStateHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
LoaderState create() => LoaderState();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(bool value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<bool>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$loaderStateHash() => r'e220e72e138a376390817c6e5a4051c7e2c665b3';
|
||||
|
||||
abstract class _$LoaderState extends $Notifier<bool> {
|
||||
bool build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref = this.ref as $Ref<bool, bool>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<bool, bool>,
|
||||
bool,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import 'package:markettakers/src/loaders/base_loader.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
|
||||
enum LoaderFlavour {
|
||||
small(filepath: 'assets/loaders/small_loaders/small_loader.riv'),
|
||||
big(filepath: 'assets/loaders/big_loaders/big_logo_splash.riv');
|
||||
|
||||
const LoaderFlavour({required this.filepath});
|
||||
|
||||
final String filepath;
|
||||
}
|
||||
|
||||
class Loader extends BaseLoader {
|
||||
final LoaderFlavour flavour;
|
||||
final bool playing;
|
||||
|
||||
Loader({super.key, required this.flavour, this.playing = false})
|
||||
: super(filepath: flavour.filepath, fit: Fit.contain);
|
||||
}
|
||||
26
pubspec.yaml
26
pubspec.yaml
@@ -1,7 +1,8 @@
|
||||
name: markettakers
|
||||
description: "MarketTakers library"
|
||||
version: 1.0.0
|
||||
publish_to: none
|
||||
name: mtcore
|
||||
description: "MarketTakers shared/core library"
|
||||
version: 1.0.7
|
||||
publish_to: https://git.markettakers.org/api/packages/MarketTakers/pub/
|
||||
repository: https://git.markettakers.org/MarketTakers/markettakers-flutter
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.2
|
||||
@@ -13,23 +14,24 @@ dependencies:
|
||||
sdk: flutter
|
||||
flutter_bloc: ^9.1.1
|
||||
flutter_hooks: ^0.21.3+1
|
||||
flutter_riverpod: ^3.0.3
|
||||
flutter_spinkit: ^5.2.2
|
||||
freezed_annotation: ^3.1.0
|
||||
hooks_riverpod: ^3.0.2
|
||||
rive: ^0.14.0-dev.9
|
||||
rive_native: ^0.0.12
|
||||
percent_indicator: ^4.2.5
|
||||
rive: ^0.14.1
|
||||
riverpod_annotation: ^4.0.0
|
||||
talker_flutter: ^5.0.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^5.0.0
|
||||
riverpod_generator: ^3.0.2
|
||||
flutter_lints: ^6.0.0
|
||||
build_runner: ^2.7.1
|
||||
freezed: ^3.2.3
|
||||
|
||||
|
||||
riverpod_generator: ^4.0.0+1
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
- assets/animations/big_loaders/
|
||||
- assets/animations/loaders/
|
||||
- assets/animations/big_loaders/big_logo_splash.riv
|
||||
- assets/animations/loaders/small_loader.riv
|
||||
|
||||
Reference in New Issue
Block a user