Skip to content

Commit

Permalink
🚀 0.5 (#40)
Browse files Browse the repository at this point in the history
* ✨ Add edit button on gem page (#39)

* 📦 Bump version
  • Loading branch information
JakesMD authored Sep 8, 2024
1 parent 7c32214 commit 730e2e3
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class _ChuckleChestAppState extends State<ChuckleChestApp> {
reevaluateListenable: ReevaluateListenable.stream(
authRepository.currentUserStream(),
),
navigatorObservers: () => [AutoRouteObserver()],
),
builder: (context, child) => Column(
children: [
Expand Down
1 change: 1 addition & 0 deletions app/lib/app/router.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:auto_route/auto_route.dart';
import 'package:cauth_repository/cauth_repository.dart';
import 'package:cgem_repository/cgem_repository.dart';
import 'package:chuckle_chest/app/guards/_guards.dart';
import 'package:chuckle_chest/pages/_pages.dart';
import 'package:flutter/material.dart';
Expand Down
17 changes: 8 additions & 9 deletions app/lib/app/router.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/lib/pages/collection/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class CCollectionPage extends StatelessWidget implements AutoRouteWrapper {
Widget build(BuildContext context) {
return BlocBuilder<CGemYearIDsFetchBloc, CGemYearIDsFetchState>(
builder: (context, state) => Scaffold(
appBar: CAppBar(context: context, title: Text(year.toString())),
body: switch (state) {
CGemYearIDsFetchInProgress() =>
const Center(child: CCradleLoadingIndicator()),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/pages/create_gem/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ class CCreateGemPage extends StatelessWidget implements AutoRouteWrapper {
}

@override
Widget build(BuildContext context) => const CEditGemPage(isNewGem: true);
Widget build(BuildContext context) => const CEditGemPage(gem: null);
}
18 changes: 12 additions & 6 deletions app/lib/pages/edit_gem/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import 'package:flutter_bloc/flutter_bloc.dart';
@RoutePage()
class CEditGemPage extends StatelessWidget implements AutoRouteWrapper {
/// {@macro CEditGemPage}
const CEditGemPage({super.key, this.isNewGem = false});
const CEditGemPage({required this.gem, super.key});

/// Whether the gem is new and should be created.
final bool isNewGem;
/// The gem to edit.
///
/// If `null`, a new gem will be created.
final CGem? gem;

@override
Widget wrappedRoute(BuildContext context) {
Expand All @@ -35,7 +37,7 @@ class CEditGemPage extends StatelessWidget implements AutoRouteWrapper {
BlocProvider<CGemEditBloc>(
create: (context) => CGemEditBloc(
gemRepository: context.read(),
gem: null,
gem: gem,
chestID: context.read<CCurrentChestCubit>().state.id,
),
),
Expand Down Expand Up @@ -72,7 +74,11 @@ class CEditGemPage extends StatelessWidget implements AutoRouteWrapper {
}

void _onSaved(BuildContext context, String gemID) {
context.router.replace(CGemRoute(gemID: gemID));
if (gem == null) {
context.router.replace(CGemRoute(gemID: gemID));
return;
}
context.router.maybePop();
}

@override
Expand All @@ -88,7 +94,7 @@ class CEditGemPage extends StatelessWidget implements AutoRouteWrapper {
appBar: CAppBar(
context: context,
title: Text(
isNewGem
gem == null
? context.cAppL10n.editGemPage_title_create
: context.cAppL10n.editGemPage_title_edit,
),
Expand Down
2 changes: 0 additions & 2 deletions app/lib/pages/gem/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:math';
import 'package:auto_route/auto_route.dart';
import 'package:cgem_repository/cgem_repository.dart';
import 'package:chuckle_chest/pages/gem/bloc/_bloc.dart';
import 'package:chuckle_chest/pages/gem/widgets/_widgets.dart';
import 'package:chuckle_chest/shared/bloc/_bloc.dart';
import 'package:chuckle_chest/shared/widgets/_widgets.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -78,7 +77,6 @@ class CGemPage extends StatelessWidget implements AutoRouteWrapper {
child: Theme(
data: Theme.of(context).copyWith(colorScheme: colorScheme),
child: Scaffold(
appBar: const CGemPageAppBar(),
body: CAnimatedGemView(gemID: gemID),
// bottomNavigationBar: CGemPageBottomAppBar(gemID: gemID),
),
Expand Down
31 changes: 30 additions & 1 deletion app/lib/shared/widgets/animated_gem.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:auto_route/auto_route.dart';
import 'package:ccore/ccore.dart';
import 'package:cgem_repository/cgem_repository.dart';
import 'package:chuckle_chest/app/router.dart';
import 'package:chuckle_chest/localization/l10n.dart';
import 'package:chuckle_chest/pages/gem/bloc/_bloc.dart';
import 'package:chuckle_chest/shared/physics/auto_scrolling.dart';
Expand Down Expand Up @@ -38,6 +40,21 @@ class _CAnimatedGemViewState extends State<CAnimatedGemView> {
return BlocBuilder<CGemFetchBloc, CGemFetchState>(
buildWhen: (_, state) => state.gemID == widget.gemID,
builder: (context, state) => Scaffold(
appBar: CAppBar(
context: context,
title: Text(
state is CGemFetchSuccess ? state.gem.number.toString() : '',
),
actions: [
if (state is CGemFetchSuccess)
IconButton(
icon: const Icon(Icons.edit_rounded),
onPressed: () => context.router.push(
CEditGemRoute(gem: state.gem),
),
),
],
),
body: switch (state) {
CGemFetchInitial() => const Center(child: CCradleLoadingIndicator()),
CGemFetchInProgress() =>
Expand Down Expand Up @@ -66,7 +83,8 @@ class CAnimatedGem extends StatefulWidget {
State<CAnimatedGem> createState() => _CAnimatedGemState();
}

class _CAnimatedGemState extends State<CAnimatedGem> {
class _CAnimatedGemState extends State<CAnimatedGem> with AutoRouteAware {
AutoRouteObserver? observer;
final scrollController = ScrollController();

Key key = UniqueKey();
Expand All @@ -91,9 +109,20 @@ class _CAnimatedGemState extends State<CAnimatedGem> {
});
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
observer = RouterScope.of(context).firstObserverOfType<AutoRouteObserver>();
if (observer != null) observer!.subscribe(this, context.routeData);
}

@override
void didPopNext() => restart();

@override
void dispose() {
scrollController.dispose();
observer?.unsubscribe(this);
super.dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: chuckle_chest
description: "A new Flutter project."
publish_to: "none"
version: 0.4.2+1
version: 0.5.0+1

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/data/database_client/lib/src/gem_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CGemClient {
)
.thenAttempt(
run: (gemID) async {
await linesTable.insert(
await linesTable.upsert(
records: lines
.map(
(line) => CLinesTableInsert(
Expand Down

0 comments on commit 730e2e3

Please sign in to comment.