@@ -198,17 +198,38 @@ class CollectionPageState extends State<CollectionPage> {
198198 return TeaCard (
199199 _getFilteredTeas (searchController.text)[i],
200200 (tea) async {
201- var future = Navigator .push (
202- context,
203- MaterialPageRoute (
204- builder: (context) => TimerPage (tea: tea),
205- ),
206- );
207- PersistenceService .bringTeaToFirstPosition (tea);
208- await future;
209- setState (() {
210- // update session info
211- });
201+ if (PersistenceService .savedSessions[_getFilteredTeas (
202+ searchController.text,
203+ )[i].id] !=
204+ null ) {
205+ await showDialog (
206+ context: context,
207+ builder: (context) {
208+ return AlertDialog (
209+ title: const Text ('Continue previous session?' ),
210+ content: const Text (
211+ 'There is a saved brewing session. Do you want to continue it?' ,
212+ ),
213+ actions: [
214+ TextButton (
215+ onPressed: () {
216+ Navigator .pop (context);
217+ },
218+ child: const Text ('Continue' ),
219+ ),
220+ TextButton (
221+ onPressed: () async {
222+ Navigator .pop (context);
223+ await PersistenceService .deleteSession (tea);
224+ },
225+ child: const Text ('Start fresh' ),
226+ ),
227+ ],
228+ );
229+ },
230+ );
231+ }
232+ await _transitionToTimerPage (context, tea);
212233 },
213234 (tea) => {
214235 showModalBottomSheet (
@@ -244,20 +265,20 @@ class CollectionPageState extends State<CollectionPage> {
244265 ),
245266 ),
246267 },
247- (tea) => {
268+ (tea) => {
248269 showDialog (
249270 context: context,
250271 barrierDismissible: false ,
251272 builder: (BuildContext context) => TeaInputDialog (
252273 Tea .copyWithGeneratedId (tea),
253- (tea) {
274+ (tea) {
254275 PersistenceService .addTea (tea).then ((value) {
255276 setState (() {});
256277 Navigator .of (context).pop ();
257278 Navigator .of (context).pop ();
258279 });
259280 },
260- (tea) {
281+ (tea) {
261282 Navigator .of (context).pop ();
262283 Navigator .of (context).pop ();
263284 },
@@ -327,4 +348,16 @@ class CollectionPageState extends State<CollectionPage> {
327348 ),
328349 );
329350 }
351+
352+ Future <void > _transitionToTimerPage (BuildContext context, Tea tea) async {
353+ var future = Navigator .push (
354+ context,
355+ MaterialPageRoute (builder: (context) => TimerPage (tea: tea)),
356+ );
357+ PersistenceService .bringTeaToFirstPosition (tea);
358+ await future;
359+ setState (() {
360+ // update session info
361+ });
362+ }
330363}
0 commit comments