Skip to content

Instantly share code, notes, and snippets.

View marcinOz's full-sized avatar
💙

Marcin marcinOz

💙
View GitHub Profile
// Assign a value to b if b is null; otherwise, b stays the same
b ??= value;
final s = ["d", "e", "f"];
final s2 = ["a", "b", "c", ...s];
print(s2); // [a, b, c, d, e, f]
var s;
final s2 = ["a", "b", "c", ...?s];
print(s2); // [a, b, c]
val s = arrayOf("d", "e", "f")
val s2 = listOf("a", "b", "c", *s)
println(s2) // [a, b, c, d, e, f]
final person = Person()
..name = "Marcin"
..surname = "Oziemski"
..age = 99
val person = Person().apply {
name = "Marcin"
surname = "Oziemski"
age = 99
}
_navigate(Store<AppState> store, action, NextDispatcher next) {
if (action is NavigatePopAction && navigatorKey.currentState.canPop()) {
navigatorKey.currentState.pop();
} else if (action is NavigatePushAction) {
if (store.state.route.last != action.routeName) {
navigatorKey.currentState.pushNamed(action.routeName);
}
}
next(action); //This need to be after name checks
}
class FabRoute<T> extends MaterialPageRoute<T> {
FabRoute(Widget widget, {RouteSettings settings})
: super(
builder: (_) => RouteAwareWidget(child: widget),
settings: settings);
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
if (settings.isInitialRoute) return child;
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
class RouteAwareWidget extends StatefulWidget {
final Widget child;
RouteAwareWidget({this.child});
State<RouteAwareWidget> createState() => RouteAwareWidgetState(child: child);
}
List<Middleware<AppState>> createNavigationMiddleware() {
return [
TypedMiddleware<AppState, NavigateReplaceAction>(_navigateReplace),
TypedMiddleware<AppState, NavigatePushAction>(_navigate),
];
}
_navigateReplace(Store<AppState> store, action, NextDispatcher next) {
final routeName = (action as NavigateReplaceAction).routeName;
if (store.state.route.last != routeName) {
floatingActionButton: FloatingActionButton(
onPressed: () => StoreProvider.of<AppState>(context)
.dispatch(NavigatePushAction(AppRoutes.addGame)),
tooltip: 'Add new game',
child: Icon(Icons.add),
),