mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
refactor: Move SortingOrderSelector into its own widget
Also translate it
This commit is contained in:
@ -133,6 +133,8 @@ widgets:
|
||||
two: "{} Notes link to this Note"
|
||||
few: "{} Notes link to this Note"
|
||||
other: "{} Notes link to this Note"
|
||||
SortingOrderSelector:
|
||||
title: Sorting Criteria
|
||||
|
||||
rootFolder: Root Folder
|
||||
ignoredFiles:
|
||||
|
@ -19,6 +19,7 @@ import 'package:gitjournal/widgets/app_bar_menu_button.dart';
|
||||
import 'package:gitjournal/widgets/app_drawer.dart';
|
||||
import 'package:gitjournal/widgets/new_note_nav_bar.dart';
|
||||
import 'package:gitjournal/widgets/note_search_delegate.dart';
|
||||
import 'package:gitjournal/widgets/sorting_order_selector.dart';
|
||||
import 'package:gitjournal/widgets/sync_button.dart';
|
||||
|
||||
enum DropDownChoices {
|
||||
@ -185,34 +186,11 @@ class _FolderViewState extends State<FolderView> {
|
||||
_scaffoldKey.currentState.removeCurrentSnackBar();
|
||||
}
|
||||
|
||||
RadioListTile<SortingMode> _buildSortingTile(SortingMode sm) {
|
||||
return RadioListTile<SortingMode>(
|
||||
title: Text(sm.toPublicString()),
|
||||
value: sm,
|
||||
groupValue: sortedNotesFolder.sortingMode,
|
||||
onChanged: (SortingMode sm) => Navigator.of(context).pop(sm),
|
||||
);
|
||||
}
|
||||
|
||||
void _sortButtonPressed() async {
|
||||
var newSortingMode = await showDialog<SortingMode>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
var children = <Widget>[
|
||||
_buildSortingTile(SortingMode.Modified),
|
||||
_buildSortingTile(SortingMode.Created),
|
||||
_buildSortingTile(SortingMode.Title),
|
||||
_buildSortingTile(SortingMode.FileName),
|
||||
];
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text("Sorting Criteria"),
|
||||
content: Column(
|
||||
children: children,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
),
|
||||
);
|
||||
},
|
||||
builder: (BuildContext context) =>
|
||||
SortingOrderSelector(sortedNotesFolder.sortingMode),
|
||||
);
|
||||
|
||||
if (newSortingMode != null) {
|
||||
|
41
lib/widgets/sorting_order_selector.dart
Normal file
41
lib/widgets/sorting_order_selector.dart
Normal file
@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
|
||||
import 'package:gitjournal/core/sorting_mode.dart';
|
||||
|
||||
class SortingOrderSelector extends StatelessWidget {
|
||||
final SortingMode selectedMode;
|
||||
|
||||
SortingOrderSelector(this.selectedMode);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var children = <Widget>[
|
||||
_buildSortingTile(context, SortingMode.Modified),
|
||||
_buildSortingTile(context, SortingMode.Created),
|
||||
_buildSortingTile(context, SortingMode.Title),
|
||||
_buildSortingTile(context, SortingMode.FileName),
|
||||
];
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(tr("widgets.SortingOrderSelector.title")),
|
||||
content: Column(
|
||||
children: children,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
RadioListTile<SortingMode> _buildSortingTile(
|
||||
BuildContext context,
|
||||
SortingMode sm,
|
||||
) {
|
||||
return RadioListTile<SortingMode>(
|
||||
title: Text(sm.toPublicString()),
|
||||
value: sm,
|
||||
groupValue: selectedMode,
|
||||
onChanged: (SortingMode sm) => Navigator.of(context).pop(sm),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user