feat: new ui (#1455)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 19:53:41 +08:00
1 parent 3be8db664c
commit 177c225f16
742 files changed
+59951 -5934

No files matched your search

@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class Breadcrumb extends StatelessWidget {
final List<String> items;
final Function(int)? onItemTap;
final TextStyle textStyle;
final TextStyle activeTextStyle;
const Breadcrumb({
super.key,
required this.items,
this.onItemTap,
this.textStyle = const TextStyle(fontSize: 16),
this.activeTextStyle =
const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
});
@override
Widget build(BuildContext context) {
List<Widget> children = [];
for (int i = 0; i < items.length; i++) {
children.add(
GestureDetector(
onTap: () {
if (onItemTap != null) {
onItemTap!(i);
}
},
child: Text(
items[i],
style: i == items.length - 1 ? activeTextStyle : textStyle,
),
),
);
if (i != items.length - 1) {
children.add(const Text(" > "));
}
}
return Row(
children: [
...(children.length == 1
? children.sublist(0, 1)
: children.sublist(0, 2)),
children.length > 2
? Expanded(
child: SingleChildScrollView(
reverse: true,
scrollDirection: Axis.horizontal,
child: Row(
children: children.sublist(2),
),
),
)
: null,
].where((e) => e != null).map((e) => e!).toList(),
).paddingOnly(right: 12);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class CheckListView extends StatefulWidget {
final List<String> items;
final List<String> checked;
final void Function(List<String> value) onChanged;
const CheckListView({
Key? key,
required this.items,
required this.checked,
required this.onChanged,
}) : super(key: key);
@override
State<CheckListView> createState() => _CheckListView();
}
class _CheckListView extends State<CheckListView> {
bool get _allChecked => _checked.length == _items.length;
List<String> get _checked => widget.checked;
List<String> get _items => widget.items;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 10),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey, width: 1),
borderRadius: BorderRadius.circular(5)),
child: Column(
children: [
CheckboxListTile(
value: _allChecked,
onChanged: (value) {
setState(() {
_checked.clear();
if (value!) {
_checked.addAll(_items);
}
widget.onChanged(_checked);
});
},
title: Text('selectAll'.tr),
),
Expanded(
child: ListView.builder(
itemCount: _items.length,
itemBuilder: (context, index) {
var item = _items[index];
return CheckboxListTile(
value: _checked.contains(item),
onChanged: (value) {
setState(() {
_checked.contains(item)
? _checked.remove(item)
: _checked.add(item);
widget.onChanged(_checked);
});
},
title: Text(item),
);
}),
),
],
));
}
}
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
class CompactCheckbox extends StatefulWidget {
final String label;
final bool value;
final ValueChanged<bool?>? onChanged;
final double? scale;
final TextStyle? textStyle;
const CompactCheckbox({
super.key,
required this.label,
required this.value,
this.onChanged,
this.scale,
this.textStyle,
});
@override
State<CompactCheckbox> createState() => _CompactCheckboxState();
}
class _CompactCheckboxState extends State<CompactCheckbox> {
late bool _value;
@override
void initState() {
super.initState();
_value = widget.value;
}
valueChanged(bool? value) {
setState(() {
_value = value!;
});
widget.onChanged?.call(_value);
}
@override
Widget build(BuildContext context) {
final checkbox = Checkbox(
value: _value,
onChanged: valueChanged,
);
return TextButton(
onPressed: () {
valueChanged(!_value);
},
child: Row(
children: [
widget.scale == null
? checkbox
: Transform.scale(
scale: widget.scale,
child: checkbox,
),
Text(
widget.label,
style: widget.textStyle,
),
],
),
);
}
}
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../util/message.dart';
class CopyButton extends StatefulWidget {
final String? url;
const CopyButton(this.url, {Key? key}) : super(key: key);
@override
State<CopyButton> createState() => _CopyButtonState();
}
class _CopyButtonState extends State<CopyButton> {
bool success = false;
copy() {
final url = widget.url;
if (url != null) {
try {
Clipboard.setData(ClipboardData(text: url));
setState(() {
success = true;
});
Future.delayed(const Duration(milliseconds: 300), () {
setState(() {
success = false;
});
});
} catch (e) {
showErrorMessage(e);
}
}
}
@override
Widget build(BuildContext context) {
return IconButton(
icon: success ? const Icon(Icons.check_circle) : const Icon(Icons.copy),
onPressed: copy,
);
}
}
@@ -0,0 +1,323 @@
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lecle_downloads_path_provider/lecle_downloads_path_provider.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:toggle_switch/toggle_switch.dart';
import '../../util/message.dart';
import '../../util/util.dart';
final deviceInfo = DeviceInfoPlugin();
// Placeholder information for download directory
class PathPlaceholder {
final String placeholder;
final String description;
final String example;
const PathPlaceholder({
required this.placeholder,
required this.description,
required this.example,
});
}
// Available placeholders for download directory
List<PathPlaceholder> getPathPlaceholders() {
final now = DateTime.now();
final year = now.year.toString();
final month = now.month.toString().padLeft(2, '0');
final day = now.day.toString().padLeft(2, '0');
return [
PathPlaceholder(
placeholder: '%year%',
description: 'placeholderYear'.tr,
example: year,
),
PathPlaceholder(
placeholder: '%month%',
description: 'placeholderMonth'.tr,
example: month,
),
PathPlaceholder(
placeholder: '%day%',
description: 'placeholderDay'.tr,
example: day,
),
PathPlaceholder(
placeholder: '%date%',
description: 'placeholderDate'.tr,
example: '$year-$month-$day',
),
];
}
// Render placeholders in a path with actual values
String renderPathPlaceholders(String path) {
if (path.isEmpty) return path;
final now = DateTime.now();
final year = now.year.toString();
final month = now.month.toString().padLeft(2, '0');
final day = now.day.toString().padLeft(2, '0');
final date = '$year-$month-$day';
return path
.replaceAll('%year%', year)
.replaceAll('%month%', month)
.replaceAll('%day%', day)
.replaceAll('%date%', date);
}
void updateDirectorySelection(
TextEditingController controller,
String value, {
VoidCallback? onChanged,
}) {
if (controller.text == value) {
return;
}
controller.value = controller.value.copyWith(
text: value,
selection: TextSelection.collapsed(offset: value.length),
composing: TextRange.empty,
);
onChanged?.call();
}
class DirectorySelector extends StatefulWidget {
final TextEditingController controller;
final bool showLabel;
final bool showAndoirdToggle;
final bool allowEdit;
final bool showPlaceholderButton;
final VoidCallback? onEditComplete;
final bool showRenderedPlaceholders;
const DirectorySelector({
Key? key,
required this.controller,
this.showLabel = true,
this.showAndoirdToggle = false,
this.allowEdit = false,
this.showPlaceholderButton = false,
this.onEditComplete,
this.showRenderedPlaceholders = false,
}) : super(key: key);
@override
State<DirectorySelector> createState() => _DirectorySelectorState();
}
class _DirectorySelectorState extends State<DirectorySelector> {
@override
Widget build(BuildContext context) {
Widget? buildSelectWidget() {
if (Util.isDesktop()) {
return IconButton(
icon: const Icon(Icons.folder_open),
onPressed: () async {
var dir = await FilePicker.platform.getDirectoryPath();
if (dir != null) {
updateDirectorySelection(widget.controller, dir,
onChanged: widget.onEditComplete);
}
});
}
// After Android 11, access to external storage is increasingly restricted, so it no longer supports selecting the download directory. However, if you do not download in external storage, all downloaded files will be deleted after the application is uninstalled.
// Fortunately, so far, most Android devices can still access the system download directory.
// For the sake of user experience, it is decided to only support selecting the application's internal directory and the system download directory. Also, a test for file write permission is performed when selecting the system download directory. If it cannot be written, selection is not allowed.
if (Util.isAndroid() && widget.showAndoirdToggle) {
final isSwitchToDownloadDir =
widget.controller.text.endsWith('/Gopeed');
return ToggleSwitch(
initialLabelIndex: isSwitchToDownloadDir ? 1 : 0,
totalSwitches: 2,
icons: const [Icons.home, Icons.download],
customWidths: const [50, 50],
onToggle: (index) async {
if (index == 0) {
updateDirectorySelection(
widget.controller,
(await getExternalStorageDirectory())?.path ??
(await getApplicationDocumentsDirectory()).path,
onChanged: widget.onEditComplete,
);
} else {
updateDirectorySelection(
widget.controller,
'${(await DownloadsPath.downloadsDirectory())!.path}/Gopeed',
onChanged: widget.onEditComplete,
);
}
},
cancelToggle: (index) async {
if (index == 0) {
return false;
}
final downloadDir =
(await DownloadsPath.downloadsDirectory())?.path;
if (downloadDir == null) {
return true;
}
// Check and request external storage permission when sdk version < 30 (android 11)
if ((await deviceInfo.androidInfo).version.sdkInt < 30) {
var status = await Permission.storage.status;
if (!status.isGranted) {
status = await Permission.storage.request();
if (!status.isGranted) {
showErrorMessage('noStoragePermission'.tr);
return true;
}
}
}
// Check write permission
final fileRandomeName =
"test_${DateTime.now().millisecondsSinceEpoch}.tmp";
final testFile = File('$downloadDir/Gopeed/$fileRandomeName');
try {
await testFile.create(recursive: true);
await testFile.writeAsString('test');
await testFile.delete();
return false;
} catch (e) {
showErrorMessage(e);
return true;
}
},
).marginOnly(left: 10);
}
return null;
}
Widget? buildPlaceholderButton() {
if (!widget.showPlaceholderButton) return null;
return PopupMenuButton<String>(
icon: const Icon(Icons.data_object),
tooltip: 'insertPlaceholder'.tr,
onSelected: (String placeholder) {
final currentText = widget.controller.text;
final selection = widget.controller.selection;
final cursorPosition = selection.baseOffset >= 0
? selection.baseOffset
: currentText.length;
final newText = currentText.substring(0, cursorPosition) +
placeholder +
currentText.substring(cursorPosition);
widget.controller.value = widget.controller.value.copyWith(
text: newText,
selection: TextSelection.fromPosition(
TextPosition(offset: cursorPosition + placeholder.length),
),
composing: TextRange.empty,
);
widget.onEditComplete?.call();
},
itemBuilder: (BuildContext context) {
final placeholders = getPathPlaceholders();
return placeholders.map((p) {
return PopupMenuItem<String>(
value: p.placeholder,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${p.placeholder} - ${p.description}',
style: const TextStyle(fontWeight: FontWeight.bold),
),
Text(
'example'.trParams({'value': p.example}),
style: TextStyle(
fontSize: 12,
color: Theme.of(context).hintColor,
),
),
],
),
);
}).toList();
},
);
}
return Row(
children: [
Expanded(
child: ValueListenableBuilder<TextEditingValue>(
valueListenable: widget.controller,
builder: (context, value, child) {
Widget? suffix;
if (widget.showRenderedPlaceholders && value.text.contains('%')) {
final renderedPath = renderPathPlaceholders(value.text);
// Show rendered path as a chip/badge in the input field
suffix = Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
margin: const EdgeInsets.only(right: 8),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.blue[200]!),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.arrow_forward,
size: 14, color: Colors.blue[700]),
const SizedBox(width: 4),
Flexible(
child: Text(
renderedPath,
style: TextStyle(
color: Colors.blue[700],
fontSize: 12,
fontWeight: FontWeight.w500,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
);
}
return TextFormField(
readOnly:
widget.allowEdit ? false : (Util.isWeb() ? false : true),
controller: widget.controller,
decoration: widget.showLabel
? InputDecoration(
labelText: 'downloadDir'.tr,
suffix: suffix,
)
: InputDecoration(
suffix: suffix,
),
validator: (v) {
return v!.trim().isNotEmpty ? null : 'downloadDirValid'.tr;
},
onEditingComplete: widget.onEditComplete,
onTapOutside: (event) {
// Call onEditComplete when user taps outside the field
widget.onEditComplete?.call();
},
);
},
)),
buildSelectWidget(),
buildPlaceholderButton(),
].where((e) => e != null).map((e) => e!).toList(),
);
}
}
@@ -0,0 +1,76 @@
import 'package:flutter/material.dart';
import '../../icon/gopeed_icons.dart';
final Map<IconData, List<String>> iconConfigMap = {
Gopeed.install: ['exe', 'msi', 'dmg', 'deb', 'rpm'],
Gopeed.android: ['apk'],
Gopeed.app_store_ios: ['ipa'],
Gopeed.file_bt: ['torrent'],
Gopeed.cd: ['iso'],
Gopeed.html5: ['html', 'htm'],
Gopeed.file_alt: ['txt', 'md', 'log', 'csv', 'tsv', 'json', 'yaml', 'yml'],
Gopeed.file_pdf: ['pdf'],
Gopeed.file_word: ['doc', 'docx'],
Gopeed.file_excel: ['xls', 'xlsx'],
Gopeed.file_powerpoint: ['ppt', 'pptx'],
Gopeed.file_archive: ['zip', 'rar', '7z', 'tar', 'gz', 'bz2', 'xz'],
Gopeed.file_image: [
'jpg',
'jpeg',
'png',
'gif',
'bmp',
'tiff',
'svg',
'webp'
],
Gopeed.file_audio: ['mp3', 'wav', 'flac', 'aac', 'ogg', 'wma', 'm4a'],
Gopeed.file_video: ['mp4', 'avi', 'mkv', 'mov', 'wmv', 'flv', 'webm'],
Gopeed.file_code: [
'js',
'css',
'json',
'xml',
'java',
'cpp',
'dart',
'py',
'rb',
'php',
'ts',
'swift',
'go',
'rs'
],
Gopeed.file: [''],
};
final Map<String, IconData> _iconCache = Map.fromEntries(
iconConfigMap.entries.expand(
(entry) => entry.value.map((ext) => MapEntry(ext, entry.key)),
),
);
String fileExt(String? name) {
if (name == null) {
return '';
}
final ext = name.split('.').last;
if (ext.length > 8) {
return '';
}
return ext.toLowerCase();
}
IconData fileIcon(String? name,
{bool isFolder = false, bool isBitTorrent = false}) {
if (isFolder) {
return isBitTorrent ? Gopeed.folder_bt : Gopeed.folder;
}
final ext = fileExt(name);
return _iconCache[ext] ?? Gopeed.file;
}
@@ -0,0 +1,296 @@
import 'package:checkable_treeview/checkable_treeview.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:toggle_switch/toggle_switch.dart';
import '../../api/model/resource.dart';
import '../../icon/gopeed_icons.dart';
import '../../util/util.dart';
import 'file_icon.dart';
import 'responsive_builder.dart';
import 'sort_icon_button.dart';
const _toggleSwitchIcons = [
Gopeed.file_video,
Gopeed.file_audio,
Gopeed.file_image,
];
const _sizeGapWidth = 72.0;
class FileTreeView extends StatefulWidget {
final List<FileInfo> files;
final List<int> initialValues;
final Function(List<int>) onSelectionChanged;
const FileTreeView(
{Key? key,
required this.files,
required this.initialValues,
required this.onSelectionChanged})
: super(key: key);
@override
State<FileTreeView> createState() => _FileTreeViewState();
}
class _FileTreeViewState extends State<FileTreeView> {
late GlobalKey<TreeViewState<int>> key;
late int totalSize;
int? toggleSwitchIndex;
@override
void initState() {
super.initState();
key = GlobalKey<TreeViewState<int>>();
totalSize = widget.files
.fold(0, (previousValue, element) => previousValue + element.size);
widget.onSelectionChanged(widget.initialValues);
}
@override
Widget build(BuildContext context) {
final selectedFileCount =
key.currentState?.getSelectedValues().where((e) => e != null).length ??
widget.files.length;
final selectedFileSize = calcSelectedSize(null);
final filterRow = InkWell(
onTap: () {},
child: ToggleSwitch(
minHeight: 32,
cornerRadius: 8,
doubleTapDisable: true,
inactiveBgColor: Theme.of(context).dividerColor,
activeBgColor: [Theme.of(context).colorScheme.primary],
initialLabelIndex: toggleSwitchIndex,
icons: _toggleSwitchIcons,
onToggle: (index) {
toggleSwitchIndex = index;
if (index == null) {
key.currentState?.setSelectedValues(List.empty());
return;
}
final iconFileExtArr = iconConfigMap[_toggleSwitchIcons[index]] ?? [];
final selectedFileIndexes = widget.files
.asMap()
.entries
.where((e) => iconFileExtArr.contains(fileExt(e.value.name)))
.map((e) => e.key)
.toList();
key.currentState?.setSelectedValues(selectedFileIndexes);
},
),
);
final countRow = Row(
children: [
Text('fileSelectedCount'.tr),
Text(
selectedFileCount.toString(),
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(width: 12),
Text('fileSelectedSize'.tr),
Text(
selectedFileCount > 0 && selectedFileSize == 0
? 'unknown'.tr
: Util.fmtByte(selectedFileSize),
style: Theme.of(context).textTheme.bodySmall,
),
],
);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Theme.of(context).dividerColor),
borderRadius: BorderRadius.circular(4),
),
child: TreeView(
key: key,
nodes: buildTreeNodes(),
showExpandCollapseButton: true,
showSelectAll: true,
onSelectionChanged: (selectedValues) {
setState(() {});
widget.onSelectionChanged(selectedValues
.where((e) => e != null)
.map((e) => e!)
.toList());
},
selectAllTrailing: (context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text('name'.tr),
SortIconButton(
onStateChanged: (state) {
switch (state) {
case SortState.asc:
key.currentState?.sort((p0, p1) {
return (p0.label as Text)
.data!
.compareTo((p1.label as Text).data!);
});
break;
case SortState.desc:
key.currentState?.sort((p0, p1) {
return (p1.label as Text)
.data!
.compareTo((p0.label as Text).data!);
});
break;
default:
key.currentState?.sort(null);
break;
}
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text('size'.tr),
SortIconButton(
onStateChanged: (state) {
switch (state) {
case SortState.asc:
key.currentState?.sort((p0, p1) {
return calcSelectedSize(p0)
.compareTo(calcSelectedSize(p1));
});
break;
case SortState.desc:
key.currentState?.sort((p0, p1) {
return calcSelectedSize(p1)
.compareTo(calcSelectedSize(p0));
});
break;
default:
key.currentState?.sort(null);
break;
}
},
),
],
)
],
);
},
),
),
),
const SizedBox(height: 12),
!ResponsiveBuilder.isNarrow(context)
? Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
filterRow,
countRow,
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
filterRow,
const SizedBox(height: 8),
countRow,
],
),
],
);
}
int calcSelectedSize(TreeNode<int>? node) {
if (key.currentState == null) {
return widget.files
.fold(0, (previousValue, element) => previousValue + element.size);
}
final selectedFileIndexes = node == null
? key.currentState?.getSelectedValues()
: (node.value != null
? [node.value]
: key.currentState?.getChildSelectedValues(node));
if (selectedFileIndexes == null) return 0;
return selectedFileIndexes.where((e) => e != null).map((e) => e!).fold(0,
(previousValue, element) => previousValue + widget.files[element].size);
}
List<TreeNode<int>> buildTreeNodes() {
final List<TreeNode<int>> rootNodes = [];
final Map<String, TreeNode<int>> dirNodes = {};
for (var i = 0; i < widget.files.length; i++) {
final file = widget.files[i];
final parts = file.path.split('/');
String currentPath = '';
TreeNode<int>? parentNode;
// Create or get directory nodes
for (final part in parts) {
if (part.isEmpty) continue;
currentPath += '/$part';
if (!dirNodes.containsKey(currentPath)) {
final node = TreeNode<int>(
label: Text(part),
icon: Icon(
fileIcon(part, isFolder: true),
size: 18,
),
trailing: (context, node) {
final size = calcSelectedSize(node);
return size > 0
? Text(Util.fmtByte(calcSelectedSize(node)),
style: Theme.of(context).textTheme.bodySmall)
: const SizedBox(width: _sizeGapWidth);
},
children: [],
);
dirNodes[currentPath] = node;
if (parentNode == null) {
rootNodes.add(node);
} else {
parentNode.children.add(node);
}
}
parentNode = dirNodes[currentPath];
}
// Create file node using file.name
final fileNode = TreeNode<int>(
label: Text(file.name),
value: i,
icon: Icon(fileIcon(file.name, isFolder: false), size: 18),
trailing: (context, node) {
return file.size > 0
? Text(Util.fmtByte(file.size),
style: Theme.of(context).textTheme.bodySmall)
: const SizedBox(width: _sizeGapWidth);
},
isSelected: widget.initialValues.contains(i),
children: [],
);
// Add file node to parent or root
if (parentNode != null) {
parentNode.children.add(fileNode);
} else {
rootNodes.add(fileNode);
}
}
return rootNodes;
}
}
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
class IconButtonLoading extends StatefulWidget {
final Widget icon;
final VoidCallback? onPressed;
final IconButtonLoadingController controller;
const IconButtonLoading(
{Key? key,
required this.icon,
required this.onPressed,
required this.controller})
: super(key: key);
@override
State<IconButtonLoading> createState() => _IconButtonLoadingState();
}
class _IconButtonLoadingState extends State<IconButtonLoading> {
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<bool>(
valueListenable: widget.controller,
builder: (context, value, child) {
return IconButton(
key: widget.key,
onPressed: value ? null : widget.onPressed,
icon: value
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
),
)
: widget.icon,
);
},
);
}
}
class IconButtonLoadingController extends ValueNotifier<bool> {
IconButtonLoadingController() : super(false);
void start() {
value = true;
}
void stop() {
value = false;
}
}
@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
class OpenInNew extends StatelessWidget {
final String text;
final String url;
const OpenInNew({super.key, required this.text, required this.url});
@override
Widget build(BuildContext context) {
return Stack(
children: [
ElevatedButton(
onPressed: () {
launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
},
style: ElevatedButton.styleFrom(
backgroundColor: Get.theme.colorScheme.background,
),
child: Row(
mainAxisSize: MainAxisSize
.min, // Set the row's size to be as small as possible
children: <Widget>[
Text(text),
const SizedBox(
width: 4), // Add some space between the text and the icon
const Icon(
Icons.open_in_new,
size: 14,
), // The icon is after the text
],
),
)
],
);
}
}
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
class OutlinedButtonLoading extends StatefulWidget {
final Widget child;
final VoidCallback onPressed;
final OutlinedButtonLoadingController controller;
const OutlinedButtonLoading(
{super.key,
required this.child,
required this.onPressed,
required this.controller});
@override
State<OutlinedButtonLoading> createState() => _OutlinedButtonLoadingState();
}
class _OutlinedButtonLoadingState extends State<OutlinedButtonLoading> {
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<bool>(
valueListenable: widget.controller,
builder: (context, value, child) {
return OutlinedButton(
key: widget.key,
onPressed: value ? null : widget.onPressed,
child: value
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
),
)
: widget.child,
);
},
);
}
}
class OutlinedButtonLoadingController extends ValueNotifier<bool> {
OutlinedButtonLoadingController() : super(false);
void start() {
value = true;
}
void stop() {
value = false;
}
}
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
class ResponsiveBuilder extends StatelessWidget {
const ResponsiveBuilder({
required this.narrowBuilder,
required this.mediumBuilder,
required this.wideBuilder,
Key? key,
}) : super(key: key);
final Widget Function(
BuildContext context,
BoxConstraints constraints,
) narrowBuilder;
final Widget Function(
BuildContext context,
BoxConstraints constraints,
) mediumBuilder;
final Widget Function(
BuildContext context,
BoxConstraints constraints,
) wideBuilder;
static bool isNarrow(BuildContext context) =>
MediaQuery.of(context).size.width < 768;
static bool isMedium(BuildContext context) =>
MediaQuery.of(context).size.width < 992 &&
MediaQuery.of(context).size.width >= 768;
static bool isWide(BuildContext context) =>
MediaQuery.of(context).size.width >= 992;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth >= 992) {
return wideBuilder(context, constraints);
} else if (constraints.maxWidth >= 768) {
return mediumBuilder(context, constraints);
} else {
return narrowBuilder(context, constraints);
}
},
);
}
}
@@ -0,0 +1,102 @@
import 'package:flutter/material.dart';
import '../../icon/gopeed_icons.dart';
enum SortState { none, asc, desc }
class SortIconButton extends StatefulWidget {
final double size;
final Color? color;
final Color? activeColor;
final SortState initialState;
final Function(SortState) onStateChanged;
const SortIconButton({
Key? key,
this.size = 18.0,
this.color,
this.activeColor,
this.initialState = SortState.none,
required this.onStateChanged,
}) : super(key: key);
@override
State<SortIconButton> createState() => _SortIconState();
}
class _SortIconState extends State<SortIconButton> {
late SortState _currentState;
@override
void initState() {
super.initState();
_currentState = widget.initialState;
}
void _toggleState() {
setState(() {
switch (_currentState) {
case SortState.none:
_currentState = SortState.asc;
break;
case SortState.asc:
_currentState = SortState.desc;
break;
case SortState.desc:
_currentState = SortState.none;
break;
}
});
widget.onStateChanged(_currentState);
}
@override
Widget build(BuildContext context) {
return InkWell(
customBorder: const CircleBorder(),
onTap: _toggleState,
child: SizedBox(
width: widget.size,
height: widget.size,
child: _currentState == SortState.none
? Icon(
Gopeed.sort,
size: widget.size,
color: widget.color,
)
: Column(
children: [
ClipRect(
child: Align(
alignment: Alignment.topCenter,
heightFactor: 0.5,
child: Icon(
Gopeed.sort,
size: widget.size,
color: _currentState == SortState.asc
? (widget.activeColor ??
Theme.of(context).colorScheme.primary)
: widget.color,
),
),
),
ClipRect(
child: Align(
alignment: Alignment.bottomCenter,
heightFactor: 0.5,
child: Icon(
Gopeed.sort,
size: widget.size,
color: _currentState == SortState.desc
? (widget.activeColor ??
Theme.of(context).colorScheme.primary)
: widget.color,
),
),
),
],
),
),
);
}
}
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
class TextButtonLoading extends StatefulWidget {
final Widget child;
final VoidCallback? onPressed;
final TextButtonLoadingController controller;
const TextButtonLoading(
{Key? key,
required this.child,
required this.onPressed,
required this.controller})
: super(key: key);
@override
State<TextButtonLoading> createState() => _TextButtonLoadingState();
}
class _TextButtonLoadingState extends State<TextButtonLoading> {
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<bool>(
valueListenable: widget.controller,
builder: (context, value, child) {
return TextButton(
key: widget.key,
onPressed: value ? null : widget.onPressed,
child: value
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
),
)
: widget.child,
);
},
);
}
}
class TextButtonLoadingController extends ValueNotifier<bool> {
TextButtonLoadingController() : super(false);
void start() {
value = true;
}
void stop() {
value = false;
}
}