Skip to content

Commit

Permalink
5.1.0
Browse files Browse the repository at this point in the history
Took 2 hours 21 minutes
  • Loading branch information
Drawner committed Sep 21, 2024
1 parent 1200a00 commit 319ccf2
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 70 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

## 5.1.0
September 20, 2024
- catchAsyncError() for mixin FutureBuilderStateMixin

## 5.0.0+3
September 04, 2024
- Remove all deprecated properties, functions, and methods
Expand Down
5 changes: 2 additions & 3 deletions example/lib/src/controller/app/app_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class ExampleAppController extends StateXController with EventsControllerMixin {
});
}

/// Supply an 'error handler' routine if something goes wrong
/// in the corresponding initAsync() routine.
/// Returns true if the error was properly handled.
/// The initAsync() function has failed and a 'error' widget will be displayed.'
/// This takes in the snapshot.error details.
@override
void onAsyncError(FlutterErrorDetails details) {}

Expand Down
10 changes: 0 additions & 10 deletions example/lib/src/controller/home/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,4 @@ class Controller extends StateXController with EventsControllerMixin {
dataObject = _model.sayHello();
}
}

/// ************** Life cycle events ****************
///
///
@override
Future<bool> initAsync() async {
// Return false to test such a circumstance
return !ExampleAppController().allowErrors;
}
}
1 change: 1 addition & 0 deletions example/lib/src/view/app/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class _MyAppState extends AppStateX<MyApp> with ClassNameMixin {
/// Demonstrate passing an 'object' down the Widget tree much like
/// how it's done using Scoped Model, but better.
object: 'Hello!',
showBinding: true, // Print event function calls
);

@override
Expand Down
3 changes: 0 additions & 3 deletions example/lib/src/view/home/page_01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import '/src/controller.dart';

import '/src/view.dart';

import 'run_state_mixins.dart';

/// The first page displayed in this app.
class Page1 extends StatefulWidget {
/// Page 1
Expand Down Expand Up @@ -111,7 +109,6 @@ class Page1State extends StateX<Page1> with EventsStateMixin<Page1> {
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const RunFutureBuilderStateMixin(), // Merely for testing
_timer.wordPair,
const Flexible(
child: Padding(
Expand Down
2 changes: 2 additions & 0 deletions example/lib/src/view/home/page_02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:example/src/view/home/run_state_mixins.dart';

import '/src/controller.dart';

import '/src/view.dart';
Expand Down
8 changes: 6 additions & 2 deletions example/lib/src/view/home/run_state_mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ class RunFutureBuilderStateMixin extends StatefulWidget {
const RunFutureBuilderStateMixin({super.key});

@override
State<StatefulWidget> createState() => _State();
State<StatefulWidget> createState() => _TestState();
}

/// Calling the 'default' functions without a subclass.
class _State extends State<StatefulWidget> with FutureBuilderStateMixin {
class _TestState extends StateX<StatefulWidget> {
_TestState() : super(useInherited: true);
@override
void initState() {
super.initState();
initAsync();
stateSet(null);
}

@override
Widget build(BuildContext context) {
buildF(context);
builder(context);
dependOnInheritedWidget(context);
return const SizedBox.shrink();
}
}
68 changes: 24 additions & 44 deletions lib/part01_statex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>

assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: initAsync() in $this');
debugPrint('============ Event: initAsync() in $this');
}
return true;
}());
Expand Down Expand Up @@ -282,8 +281,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>

assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: initState() in $this');
debugPrint('============ Event: initState() in $this');
}
return true;
}());
Expand Down Expand Up @@ -315,8 +313,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>

assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didChangeDependencies() in $this');
debugPrint('============ Event: didChangeDependencies() in $this');
}
return true;
}());
Expand Down Expand Up @@ -372,8 +369,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>

assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: activate() in $this');
debugPrint('============ Event: activate() in $this');
}
return true;
}());
Expand Down Expand Up @@ -418,8 +414,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
//
// assert(() {
// if (kDebugMode) {
// //ignore: avoid_print
// print('============ _copyOverState(): $this copied $oldStateX');
// debugPrint('============ _copyOverState(): $this copied $oldStateX');
// }
// return true;
// }());
Expand Down Expand Up @@ -485,8 +480,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>

assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: deactivate() in $this');
debugPrint('============ Event: deactivate() in $this');
}
return true;
}());
Expand Down Expand Up @@ -528,8 +522,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>

assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: dispose() in $this');
debugPrint('============ Event: dispose() in $this');
}
return true;
}());
Expand Down Expand Up @@ -566,8 +559,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didUpdateWidget() in $this');
debugPrint('============ Event: didUpdateWidget() in $this');
}
return true;
}());
Expand Down Expand Up @@ -756,8 +748,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didRequestAppExit() in $this');
debugPrint('============ Event: didRequestAppExit() in $this');
}
return true;
}());
Expand Down Expand Up @@ -815,8 +806,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didPopRoute() in $this');
debugPrint('============ Event: didPopRoute() in $this');
}
return true;
}());
Expand Down Expand Up @@ -866,8 +856,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didPushRouteInformation() in $this');
debugPrint('============ Event: didPushRouteInformation() in $this');
}
return true;
}());
Expand Down Expand Up @@ -905,8 +894,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didPopNext() in $this');
debugPrint('============ Event: didPopNext() in $this');
}
return true;
}());
Expand Down Expand Up @@ -942,8 +930,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didPush() in $this');
debugPrint('============ Event: didPush() in $this');
}
return true;
}());
Expand Down Expand Up @@ -979,8 +966,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didPop() in $this');
debugPrint('============ Event: didPop() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1016,8 +1002,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didPushNext() in $this');
debugPrint('============ Event: didPushNext() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1073,8 +1058,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didChangeMetrics() in $this');
debugPrint('============ Event: didChangeMetrics() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1125,8 +1109,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didChangeTextScaleFactor() in $this');
debugPrint('============ Event: didChangeTextScaleFactor() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1165,8 +1148,8 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didChangePlatformBrightness() in $this');
debugPrint(
'============ Event: didChangePlatformBrightness() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1210,8 +1193,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didChangeLocales() in $this');
debugPrint('============ Event: didChangeLocales() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1254,8 +1236,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didHaveMemoryPressure() in $this');
debugPrint('============ Event: didHaveMemoryPressure() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1297,8 +1278,8 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: didChangeAccessibilityFeatures() in $this');
debugPrint(
'============ Event: didChangeAccessibilityFeatures() in $this');
}
return true;
}());
Expand Down Expand Up @@ -1334,8 +1315,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
// Record the triggered event
assert(() {
if (_showWidgetsBinding) {
//ignore: avoid_print
print('============ Event: reassemble() in $this');
debugPrint('============ Event: reassemble() in $this');
}
return true;
}());
Expand Down
22 changes: 18 additions & 4 deletions lib/part05_futurebuilder_state_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ mixin FutureBuilderStateMixin on State {
// Generate the Future evey time or just once
if (_runAsync || _future == null) {
_future = initAsync();
_future?.catchError(
(Object e) {
catchAsyncError(e);
// Always false. snapshot.data == false
// snapshot.hasError likely true so ErrorWidget.builder() displayed
return false;
},
// It's got to be handled, and so it's always true to call catchError()
test: (_) => true,
);
}
return FutureBuilder<bool>(
key: ValueKey<State>(this),
Expand Down Expand Up @@ -60,6 +70,14 @@ mixin FutureBuilderStateMixin on State {
AsyncSnapshot<bool>? get snapshot => _snapshot;
AsyncSnapshot<bool>? _snapshot;

/// initAsync() has failed and a 'error' widget instead will be displayed.
/// This takes in the snapshot.error details.
void onAsyncError(FlutterErrorDetails details) {}

/// Catch it if the initAsync() throws an error
/// The FutureBuilder will fail, but you can examine the error
void catchAsyncError(Object error) {}

/// Record any splash screen
Widget? _splashScreen;

Expand Down Expand Up @@ -195,10 +213,6 @@ mixin FutureBuilderStateMixin on State {
return widget;
}

/// Supply an 'error handler' routine if something goes wrong
/// in the corresponding runAsync() or initAsync() routine.
void onAsyncError(FlutterErrorDetails details) {}

/// Is the CupertinoApp being used?
bool get usingCupertino =>
_usingCupertino ??= context.getElementForInheritedWidgetOfExactType<
Expand Down
4 changes: 2 additions & 2 deletions lib/part18_async_ops_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ mixin AsyncOps {
/// Implement any asynchronous operations needed done at start up.
Future<bool> initAsync() async => true;

/// Supply an 'error handler' routine if something goes wrong
/// in the corresponding runAsync() routine.
/// initAsync() has failed and a 'error' widget instead will be displayed.
/// This takes in the snapshot.error details.
void onAsyncError(FlutterErrorDetails details) {}

///
Expand Down
1 change: 0 additions & 1 deletion lib/part19_uuid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

part of 'state_extended.dart';

/// A UUID generator, useful for generating unique IDs.
/// Shamelessly extracted from the author of Scoped Model plugin,
/// Who maybe took from the Flutter source code. I'm not telling!
///
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: state_extended
description: This class extends the capabilities of Flutter's State class and includes a controller.
version: 5.0.0+3
version: 5.1.0
homepage: https://www.andrioussolutions.com
repository: https://github.com/AndriousSolutions/state_extended

Expand Down

0 comments on commit 319ccf2

Please sign in to comment.