refactor(bootstapper): migration to riverpod
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mtcore/markettakers.dart';
|
||||
import 'package:mtcore/src/credits.dart';
|
||||
import 'package:mtcore/src/loader.dart';
|
||||
import 'package:talker_flutter/talker_flutter.dart';
|
||||
|
||||
class AboutScreen extends StatelessWidget {
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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:mtcore/src/loader.dart';
|
||||
import 'package:percent_indicator/circular_percent_indicator.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'bootstrapper.g.dart';
|
||||
part 'bootstrapper.freezed.dart';
|
||||
|
||||
abstract class StageFactory {
|
||||
@@ -25,121 +27,86 @@ sealed class Progress with _$Progress {
|
||||
const factory Progress.indefinite() = IndefiniteProgress;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class StageState with _$StageState {
|
||||
final String title;
|
||||
final Progress progress;
|
||||
class StageState {
|
||||
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: const Progress.indefinite()));
|
||||
typedef Stages = List<StageFactory>;
|
||||
|
||||
@riverpod
|
||||
class CurrentStage extends _$CurrentStage {
|
||||
@override
|
||||
StageState? build() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void set(StageState newState) {
|
||||
state = newState;
|
||||
}
|
||||
|
||||
void setProgress(Progress progress) {
|
||||
state?.progress = progress;
|
||||
}
|
||||
|
||||
void setTitle(String title) {
|
||||
state?.title = title;
|
||||
}
|
||||
}
|
||||
|
||||
class StageController {
|
||||
final Ref _ref;
|
||||
StageController(this._ref);
|
||||
|
||||
void setDefiniteProgress(double value) {
|
||||
emit(state.copyWith(progress: Progress.definite(value)));
|
||||
if (!_ref.mounted) return;
|
||||
_ref
|
||||
.read(currentStageProvider.notifier)
|
||||
.setProgress(Progress.definite(value));
|
||||
}
|
||||
|
||||
void setIndefiniteProgress() {
|
||||
emit(state.copyWith(progress: const Progress.indefinite()));
|
||||
if (!_ref.mounted) return;
|
||||
_ref.read(currentStageProvider.notifier).setProgress(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;
|
||||
|
||||
StageFactory get currentStage => stages[currentStageIndex];
|
||||
bool get areStagesCompleted => currentStageIndex >= stages.length;
|
||||
|
||||
BootstrapState(this.stages, {this.currentStageIndex = 0, this.controller});
|
||||
}
|
||||
|
||||
@freezed
|
||||
sealed class _BootstrapEvent with _$BootstrapEvent {
|
||||
const factory _BootstrapEvent.start() = StartEvent;
|
||||
const factory _BootstrapEvent.stageCompleted() = StageCompletedEvent;
|
||||
}
|
||||
|
||||
class _BootstrapController extends Bloc<_BootstrapEvent, BootstrapState> {
|
||||
final Completer<void> completer;
|
||||
_BootstrapController(super.initialState, this.completer) {
|
||||
assert(state.stages.isNotEmpty, "Stages list cannot be empty");
|
||||
|
||||
on<StartEvent>((event, emit) async {
|
||||
talker.info("BootstrapController: Starting bootstrap process");
|
||||
|
||||
if (await state.currentStage.isAlreadyCompleted) {
|
||||
add(const _BootstrapEvent.stageCompleted());
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// all stages completed
|
||||
if (newState.areStagesCompleted) {
|
||||
talker.info("BootstrapController: All stages completed");
|
||||
completer.complete();
|
||||
return;
|
||||
}
|
||||
|
||||
// skip already completed stages
|
||||
if (await newState.currentStage.isAlreadyCompleted) {
|
||||
talker.info(
|
||||
"BootstrapController: Stage ${newState.currentStage.title} already completed, skipping",
|
||||
);
|
||||
emit(newState);
|
||||
add(const _BootstrapEvent.stageCompleted());
|
||||
return;
|
||||
}
|
||||
|
||||
// move to next stage
|
||||
final nextStage = newState.currentStage;
|
||||
talker.info("BootstrapController: Starting stage ${nextStage.title}");
|
||||
launchCurrentStage(state.stages, nextIndex);
|
||||
emit(newState);
|
||||
});
|
||||
Future<bool> build() async {
|
||||
return false;
|
||||
}
|
||||
|
||||
StageController launchCurrentStage(Stages stages, int index) {
|
||||
final currentStage = stages[index];
|
||||
final controller = StageController(title: currentStage.title);
|
||||
void start(Stages stages) async {
|
||||
if (_hasStarted) return;
|
||||
_hasStarted = true;
|
||||
|
||||
currentStage
|
||||
.start(controller)
|
||||
.then((_) {
|
||||
add(_BootstrapEvent.stageCompleted());
|
||||
})
|
||||
.catchError((error) {
|
||||
talker.handle(
|
||||
error,
|
||||
null,
|
||||
"BootstrapController: Error in ${currentStage.title}",
|
||||
);
|
||||
addError(error);
|
||||
});
|
||||
state = AsyncValue.loading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
for (final stage in stages) {
|
||||
talker.info("${stage.title} starting");
|
||||
|
||||
return controller;
|
||||
ref
|
||||
.read(currentStageProvider.notifier)
|
||||
.set(
|
||||
StageState(title: stage.title, progress: Progress.indefinite()),
|
||||
);
|
||||
|
||||
await stage.start(StageController(ref));
|
||||
talker.info("${stage.title} completed");
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,63 +117,61 @@ class _DefiniteIndicator extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final formattedProgress = "${(progress * 100).toStringAsFixed(0)}%";
|
||||
return CircularPercentIndicator(
|
||||
radius: 40.0,
|
||||
lineWidth: 5.0,
|
||||
percent: progress.clamp(0.0, 1.0),
|
||||
center: Text(formattedProgress),
|
||||
progressColor: Theme.of(context).colorScheme.secondary,
|
||||
final value = progress.clamp(0.0, 1.0);
|
||||
return LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final side = (c.hasBoundedWidth && c.hasBoundedHeight)
|
||||
? (c.maxWidth < c.maxHeight ? c.maxWidth : c.maxHeight)
|
||||
: 80.0; // sensible fallback if unconstrained
|
||||
|
||||
final radius = side / 2;
|
||||
|
||||
final formattedProgress = "${(progress * 100).toStringAsFixed(0)}%";
|
||||
return CircularPercentIndicator(
|
||||
radius: radius * 2,
|
||||
lineWidth: 5.0,
|
||||
percent: value,
|
||||
center: Text(formattedProgress),
|
||||
progressColor: Theme.of(context).colorScheme.secondary,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// return CircularProgressIndicator(value: value);
|
||||
}
|
||||
}
|
||||
|
||||
class _BootstrapFooter extends StatelessWidget {
|
||||
class _BootstrapFooter extends ConsumerWidget {
|
||||
const _BootstrapFooter();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<_BootstrapController, BootstrapState>(
|
||||
builder: (context, state) {
|
||||
if (state.areStagesCompleted) {
|
||||
return Text(
|
||||
"All stages completed",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
);
|
||||
} else if (state.controller != null) {
|
||||
return BlocBuilder<StageController, StageState>(
|
||||
bloc: state.controller,
|
||||
builder: (context, state) {
|
||||
final progressIndicator = state.progress.when(
|
||||
definite: (definite) => _DefiniteIndicator(progress: definite),
|
||||
indefinite: () => const CircularProgressIndicator(),
|
||||
);
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final state = ref.watch(currentStageProvider);
|
||||
if (state == null) return Container();
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: Text(
|
||||
state.title,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
Flexible(flex: 1, child: progressIndicator),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
final progressIndicator = state.progress.when(
|
||||
definite: (definite) => _DefiniteIndicator(progress: definite),
|
||||
indefinite: () => SpinKitCubeGrid(color: Colors.white),
|
||||
);
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: Text(
|
||||
state.title,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
Flexible(flex: 1, child: progressIndicator),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Bootstrapper extends StatelessWidget {
|
||||
class Bootstrapper extends HookConsumerWidget {
|
||||
final Stages stages;
|
||||
final Completer onCompleted;
|
||||
|
||||
@@ -217,36 +182,27 @@ class Bootstrapper extends StatelessWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) {
|
||||
final controller = _BootstrapController(
|
||||
BootstrapState(stages),
|
||||
onCompleted,
|
||||
);
|
||||
controller.add(const _BootstrapEvent.start());
|
||||
return controller;
|
||||
},
|
||||
child: BlocListener<_BootstrapController, BootstrapState>(
|
||||
listener: (context, state) {
|
||||
if (state.areStagesCompleted) {
|
||||
onCompleted.complete();
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: Center(child: Loader.playing(flavour: LoaderFlavour.big)),
|
||||
),
|
||||
Flexible(flex: 1, child: Container()),
|
||||
Flexible(flex: 1, child: _BootstrapFooter()),
|
||||
Flexible(flex: 1, child: Container()),
|
||||
],
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
Future(() async => ref.read(stagesWorkerProvider.notifier).start(stages));
|
||||
final work = ref.watch(stagesWorkerProvider);
|
||||
|
||||
if (!onCompleted.isCompleted) {
|
||||
if (work.hasError) onCompleted.completeError(work.error!);
|
||||
if (work.hasValue && work.value!) onCompleted.complete();
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: Center(child: Loader.playing(flavour: LoaderFlavour.big)),
|
||||
),
|
||||
),
|
||||
Flexible(flex: 1, child: Container()),
|
||||
Flexible(flex: 1, child: _BootstrapFooter()),
|
||||
Flexible(flex: 1, child: Container()),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,601 +269,4 @@ String toString() {
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$StageState {
|
||||
|
||||
String get title; Progress get progress;
|
||||
/// Create a copy of StageState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$StageStateCopyWith<StageState> get copyWith => _$StageStateCopyWithImpl<StageState>(this as StageState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is StageState&&(identical(other.title, title) || other.title == title)&&(identical(other.progress, progress) || other.progress == progress));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,title,progress);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'StageState(title: $title, progress: $progress)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $StageStateCopyWith<$Res> {
|
||||
factory $StageStateCopyWith(StageState value, $Res Function(StageState) _then) = _$StageStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String title, Progress progress
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$StageStateCopyWithImpl<$Res>
|
||||
implements $StageStateCopyWith<$Res> {
|
||||
_$StageStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final StageState _self;
|
||||
final $Res Function(StageState) _then;
|
||||
|
||||
/// Create a copy of StageState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? title = null,Object? progress = null,}) {
|
||||
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 Progress,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [StageState].
|
||||
extension StageStatePatterns on StageState {
|
||||
/// 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 _$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,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 _:
|
||||
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,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent():
|
||||
return start(_that);case StageCompletedEvent():
|
||||
return stageCompleted(_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,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent() when start != null:
|
||||
return start(_that);case StageCompletedEvent() when stageCompleted != null:
|
||||
return stageCompleted(_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,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent() when start != null:
|
||||
return start();case StageCompletedEvent() when stageCompleted != null:
|
||||
return stageCompleted();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,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent():
|
||||
return start();case StageCompletedEvent():
|
||||
return stageCompleted();}
|
||||
}
|
||||
/// 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,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case StartEvent() when start != null:
|
||||
return start();case StageCompletedEvent() when stageCompleted != null:
|
||||
return stageCompleted();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()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// dart format on
|
||||
|
||||
108
lib/src/bootstrapper.g.dart
Normal file
108
lib/src/bootstrapper.g.dart
Normal file
@@ -0,0 +1,108 @@
|
||||
// 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)
|
||||
const currentStageProvider = CurrentStageProvider._();
|
||||
|
||||
final class CurrentStageProvider
|
||||
extends $NotifierProvider<CurrentStage, StageState?> {
|
||||
const 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'9f294430d9b3fb21fd51f97163443b56bd152855';
|
||||
|
||||
abstract class _$CurrentStage extends $Notifier<StageState?> {
|
||||
StageState? build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref = this.ref as $Ref<StageState?, StageState?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<StageState?, StageState?>,
|
||||
StageState?,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
|
||||
@ProviderFor(StagesWorker)
|
||||
const stagesWorkerProvider = StagesWorkerProvider._();
|
||||
|
||||
final class StagesWorkerProvider
|
||||
extends $AsyncNotifierProvider<StagesWorker, bool> {
|
||||
const 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'68f4d51d98fa27e17496e24e4b8eeeca1815f323';
|
||||
|
||||
abstract class _$StagesWorker extends $AsyncNotifier<bool> {
|
||||
FutureOr<bool> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref = this.ref as $Ref<AsyncValue<bool>, bool>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<bool>, bool>,
|
||||
AsyncValue<bool>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user