-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rares45/improve-example
New and improved example
- Loading branch information
Showing
12 changed files
with
508 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:master_detail_flow/master_detail_flow.dart'; | ||
|
||
/// To create your custom DetailsItem all you need is to get the flow's settings | ||
/// by using `MasterDetailsFlowSettings.of(context)` then you just need to | ||
/// override all the ways to go back, including the app bar ones, so disable | ||
/// implyLeading on all app bars | ||
class CustomDetailsItem extends StatelessWidget { | ||
const CustomDetailsItem({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
MasterDetailsFlowSettings? settings = MasterDetailsFlowSettings.of(context); | ||
bool selfPage = settings?.selfPage ?? false; | ||
return WillPopScope( | ||
// WillPopScope overrides the system back button so we move back the flow | ||
onWillPop: () async { | ||
if (settings?.selfPage == true) { | ||
settings!.goBack!(); | ||
} | ||
return !(settings?.selfPage ?? false); | ||
}, | ||
child: SizedBox.expand( | ||
child: Center( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text(selfPage ? 'This is a page' : 'This is a panel'), | ||
FilledButton.tonalIcon( | ||
onPressed: settings?.goBack, | ||
icon: Icon(Icons.adaptive.arrow_back_rounded), | ||
label: const Text('Go back'), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class PageCustom extends StatelessWidget { | ||
const PageCustom({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: MasterDetailsFlow( | ||
title: const Text('Custom DetailsItem'), | ||
items: [ | ||
MasterItem( | ||
'Custom', | ||
detailsBuilder: (context) => const CustomDetailsItem(), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:master_detail_flow/master_detail_flow.dart'; | ||
|
||
class PageFuture extends StatelessWidget { | ||
const PageFuture({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FutureBuilder( | ||
future: Future.delayed( | ||
const Duration(seconds: 5), | ||
() => [ | ||
MasterItem( | ||
'From future 1', | ||
leading: const Icon(Icons.settings_rounded), | ||
detailsBuilder: (context) => | ||
const DetailsItem(title: Text('')), | ||
), | ||
MasterItem( | ||
'From future 2', | ||
leading: const Icon(Icons.flutter_dash_rounded), | ||
detailsBuilder: (context) => | ||
const DetailsItem(title: Text('')), | ||
), | ||
]), | ||
builder: (context, snapshot) { | ||
return Scaffold( | ||
body: MasterDetailsFlow( | ||
title: const Text('Future'), | ||
nothingSelectedWidget: | ||
snapshot.connectionState == ConnectionState.done | ||
? null | ||
: Container(), // Used to hide the selection text | ||
items: snapshot.connectionState == ConnectionState.done | ||
? snapshot.data! | ||
: [ | ||
const _MasterLoading(), | ||
], | ||
), | ||
); | ||
}); | ||
} | ||
} | ||
|
||
/// Custom MasterItem | ||
class _MasterLoading extends StatelessWidget implements MasterItemBase { | ||
const _MasterLoading({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const SizedBox( | ||
height: 200, | ||
child: Center( | ||
child: CircularProgressIndicator(), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.