Skip to content

Commit

Permalink
Upgrade dropdowns to material 3
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 29, 2023
1 parent 929635b commit 8c310aa
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 101 deletions.
39 changes: 16 additions & 23 deletions app/lib/pages/calendar/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,32 +217,25 @@ class _CalendarItemDialogState extends State<CalendarItemDialog> {
},
),
const SizedBox(height: 16),
DropdownButtonFormField<EventStatus>(
value: _item.status,
items: EventStatus.values
.map<DropdownMenuItem<EventStatus>>((value) {
return DropdownMenuItem<EventStatus>(
value: value,
child: Row(
children: [
PhosphorIcon(
value.icon(PhosphorIconsStyle.light),
color: value.getColor()),
const SizedBox(width: 8),
Text(value.getLocalizedName(context)),
],
),
);
}).toList(),
onChanged: (EventStatus? value) {
DropdownMenu<EventStatus>(
initialSelection: _item.status,
dropdownMenuEntries: EventStatus.values
.map((value) => DropdownMenuEntry<EventStatus>(
value: value,
leadingIcon: PhosphorIcon(
value.icon(PhosphorIconsStyle.light),
color: value.getColor()),
label: value.getLocalizedName(context),
))
.toList(),
onSelected: (EventStatus? value) {
_item =
_item.copyWith(status: value ?? _item.status);
},
decoration: InputDecoration(
labelText: AppLocalizations.of(context).status,
icon: const PhosphorIcon(PhosphorIconsLight.info),
border: const OutlineInputBorder(),
),
label: Text(AppLocalizations.of(context).status),
leadingIcon:
const PhosphorIcon(PhosphorIconsLight.info),
expandedInsets: const EdgeInsets.all(4),
),
const SizedBox(height: 16),
TextFormField(
Expand Down
59 changes: 35 additions & 24 deletions app/lib/pages/notes/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ class NotesBodyView extends StatefulWidget {
class _NotesBodyViewState extends State<NotesBodyView> {
late final FlowCubit _flowCubit;
late final SourcedPagingController<Note> _controller;
late final Future<Note?> _parent;
late NoteFilter _filter;

@override
void initState() {
_flowCubit = context.read<FlowCubit>();
_parent = _fetchParent();
_controller = SourcedPagingController(_flowCubit);
_controller.addFetchListener((source, service, offset, limit) async {
if (_filter.source != null && _filter.source != source) return null;
Expand All @@ -177,17 +179,21 @@ class _NotesBodyViewState extends State<NotesBodyView> {
search: widget.search);
if (notes == null) return null;
if (source != widget.parent?.source) return notes;
final parent = await service.note?.getNote(widget.parent!.model);
if (parent == null) return notes;
return [
parent,
...notes,
];
return notes;
});
_filter = widget.filter;
super.initState();
}

Future<Note?> _fetchParent() async {
if (widget.parent == null) return null;
final parent = await _flowCubit
.getService(widget.parent!.source)
.note
?.getNote(widget.parent!.model);
return parent;
}

@override
void dispose() {
_controller.dispose();
Expand All @@ -214,6 +220,24 @@ class _NotesBodyViewState extends State<NotesBodyView> {
return Scaffold(
body: Column(
children: [
FutureBuilder<Note?>(
future: _parent,
builder: (context, snapshot) {
final data = snapshot.data;
if (data == null) return Container();
return Column(
children: [
NoteCard(
controller: _controller,
source: widget.parent!.source,
primary: true,
note: data,
),
const SizedBox(height: 8),
const Divider(),
],
);
}),
NoteFilterView(
initialFilter: _filter,
onChanged: (filter) {
Expand All @@ -229,24 +253,11 @@ class _NotesBodyViewState extends State<NotesBodyView> {
pagingController: _controller,
builderDelegate: buildMaterialPagedDelegate<SourcedModel<Note>>(
_controller,
(ctx, item, index) {
final primary = item.source == widget.parent?.source &&
item.model.id == widget.parent?.model;
return Column(
children: [
NoteCard(
controller: _controller,
source: item.source,
note: item.model,
primary: primary,
),
if (primary) ...[
const SizedBox(height: 8),
const Divider(),
]
],
);
},
(ctx, item, index) => NoteCard(
controller: _controller,
source: item.source,
note: item.model,
),
),
),
),
Expand Down
27 changes: 9 additions & 18 deletions app/lib/widgets/source_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,16 @@ class SourceDropdown<T> extends StatelessWidget {
return Column(
children: [
const SizedBox(height: 16),
DropdownButtonFormField<String>(
value: value,
items: services.entries.map<DropdownMenuItem<String>>((value) {
DropdownMenu<String>(
initialSelection: value,
dropdownMenuEntries: services.entries.map((value) {
final remote = cubit.sourcesService.getRemote(value.key);
return DropdownMenuItem<String>(
return DropdownMenuEntry<String>(
value: value.key,
child: Text(
remote?.displayName ?? AppLocalizations.of(context).local),
label: remote?.displayName ?? AppLocalizations.of(context).local,
);
}).toList(),
selectedItemBuilder: (context) {
return [
...remotes.map<Widget>((value) =>
Text(value?.uri.host ?? AppLocalizations.of(context).local))
];
},
onChanged: (value) {
onSelected: (value) {
final service = services[value];
onChanged(
service == null
Expand All @@ -64,11 +57,9 @@ class SourceDropdown<T> extends StatelessWidget {
),
);
},
decoration: InputDecoration(
labelText: AppLocalizations.of(context).source,
icon: const PhosphorIcon(PhosphorIconsLight.cloud),
border: const OutlineInputBorder(),
),
label: Text(AppLocalizations.of(context).source),
leadingIcon: const PhosphorIcon(PhosphorIconsLight.cloud),
expandedInsets: const EdgeInsets.all(4),
),
],
);
Expand Down
68 changes: 34 additions & 34 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ packages:
dependency: transitive
description:
name: coverage
sha256: "0cec992efb6feaa6141779723bf0119d5f511ebd658aa5225d9bac53cb7e609e"
sha256: ac86d3abab0f165e4b8f561280ff4e066bceaac83c424dd19f1ae2c2fcd12ca9
url: "https://pub.dev"
source: hosted
version: "1.7.0"
version: "1.7.1"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -246,10 +246,10 @@ packages:
dependency: transitive
description:
name: dev_test
sha256: "71b1bd01bb2068794aa6aab9e45ecd5257b5f3b5ca52903b12fcb5d56fe862bb"
sha256: "8a4aaca13079c6ca8f96124eb9c4fb45b71629ea9f2af052e42634aacae573ae"
url: "https://pub.dev"
source: hosted
version: "0.16.2+3"
version: "0.16.3"
dynamic_color:
dependency: "direct main"
description:
Expand Down Expand Up @@ -383,10 +383,10 @@ packages:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: f185ac890306b5779ecbd611f52502d8d4d63d27703ef73161ca0407e815f02c
sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da
url: "https://pub.dev"
source: hosted
version: "2.0.16"
version: "2.0.17"
flutter_secure_storage:
dependency: "direct main"
description:
Expand Down Expand Up @@ -489,10 +489,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: a206cc4621a644531a2e05e7774616ab4d9d85eab1f3b0e255f3102937fccab1
sha256: e156bc1b2088eb5ece9351bccd48c3e1719a4858eacbd44e59162e98a68205d1
url: "https://pub.dev"
source: hosted
version: "12.0.0"
version: "12.0.1"
graphs:
dependency: transitive
description:
Expand Down Expand Up @@ -714,10 +714,10 @@ packages:
dependency: transitive
description:
name: path_provider_android
sha256: "6b8b19bd80da4f11ce91b2d1fb931f3006911477cec227cce23d3253d80df3f1"
sha256: e595b98692943b4881b219f0a9e3945118d3c16bd7e2813f98ec6e532d905f72
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.2.1"
path_provider_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -795,10 +795,10 @@ packages:
dependency: transitive
description:
name: process_run
sha256: ceacfac6d566a36c895d64edc7e429efb2d6b6303b5e28d5c13bc59fe6e8974e
sha256: "1cb96f835ec02ba1a35af4e6f99f937618023b6d2ffba88f0c0f1041af2e9f12"
url: "https://pub.dev"
source: hosted
version: "0.13.1"
version: "0.13.2"
provider:
dependency: transitive
description:
Expand Down Expand Up @@ -1096,10 +1096,10 @@ packages:
dependency: transitive
description:
name: test
sha256: d983a57c33dde6d44b1fb8635f67c91f4b41d26cf227c147963affa97d63563d
sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f
url: "https://pub.dev"
source: hosted
version: "1.24.8"
version: "1.24.9"
test_api:
dependency: "direct overridden"
description:
Expand All @@ -1112,10 +1112,10 @@ packages:
dependency: transitive
description:
name: test_core
sha256: "2f866bf4b20c11327ac166ee6036bddafb7fe9e35505ff8324f788e66913f967"
sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a
url: "https://pub.dev"
source: hosted
version: "0.5.8"
version: "0.5.9"
timing:
dependency: transitive
description:
Expand All @@ -1136,66 +1136,66 @@ packages:
dependency: "direct main"
description:
name: url_launcher
sha256: "47e208a6711459d813ba18af120d9663c20bdf6985d6ad39fe165d2538378d27"
sha256: b1c9e98774adf8820c96fbc7ae3601231d324a7d5ebd8babe27b6dfac91357ba
url: "https://pub.dev"
source: hosted
version: "6.1.14"
version: "6.2.1"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: b04af59516ab45762b2ca6da40fa830d72d0f6045cd97744450b73493fa76330
sha256: "31222ffb0063171b526d3e569079cf1f8b294075ba323443fdc690842bfd4def"
url: "https://pub.dev"
source: hosted
version: "6.1.0"
version: "6.2.0"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "7c65021d5dee51813d652357bc65b8dd4a6177082a9966bc8ba6ee477baa795f"
sha256: "4ac97281cf60e2e8c5cc703b2b28528f9b50c8f7cebc71df6bdf0845f647268a"
url: "https://pub.dev"
source: hosted
version: "6.1.5"
version: "6.2.0"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: b651aad005e0cb06a01dbd84b428a301916dc75f0e7ea6165f80057fee2d8e8e
sha256: "9f2d390e096fdbe1e6e6256f97851e51afc2d9c423d3432f1d6a02a8a9a8b9fd"
url: "https://pub.dev"
source: hosted
version: "3.0.6"
version: "3.1.0"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: b55486791f666e62e0e8ff825e58a023fd6b1f71c49926483f1128d3bbd8fe88
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
url: "https://pub.dev"
source: hosted
version: "3.0.7"
version: "3.1.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "95465b39f83bfe95fcb9d174829d6476216f2d548b79c38ab2506e0458787618"
sha256: "980e8d9af422f477be6948bdfb68df8433be71f5743a188968b0c1b887807e50"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
version: "2.2.0"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "2942294a500b4fa0b918685aff406773ba0a4cd34b7f42198742a94083020ce5"
sha256: "7fd2f55fe86cea2897b963e864dc01a7eb0719ecc65fcef4c1cc3d686d718bb2"
url: "https://pub.dev"
source: hosted
version: "2.0.20"
version: "2.2.0"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "95fef3129dc7cfaba2bc3d5ba2e16063bb561fc6d78e63eee16162bc70029069"
sha256: "7754a1ad30ee896b265f8d14078b0513a4dba28d358eabb9d5f339886f4a1adc"
url: "https://pub.dev"
source: hosted
version: "3.0.8"
version: "3.1.0"
vector_math:
dependency: transitive
description:
Expand All @@ -1208,10 +1208,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: a13d5503b4facefc515c8c587ce3cf69577a7b064a9f1220e005449cf1f64aad
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "12.0.0"
version: "13.0.0"
watcher:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit 8c310aa

Please sign in to comment.