Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/router/wallet/wallet_receive_invoice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'package:yana/main.dart';
import 'package:yana/provider/nwc_provider.dart';
import 'package:yana/utils/base.dart';
import 'package:yana/utils/string_util.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../i18n/i18n.dart';

import '../../ui/button.dart';
import '../../utils/platform_util.dart';
Expand Down Expand Up @@ -192,6 +194,7 @@ class _WalletReceiveRouter extends State<WalletReceiveInvoiceRouter> {
before: const Icon(Icons.copy, color: Colors.white),
text: "Copy ",
onTap: () async {
print("[WalletReceiveInvoiceRouter] Copy button tapped.");
_doCopy(payingInvoice!);
}))
]));
Expand Down Expand Up @@ -433,9 +436,14 @@ class _WalletReceiveRouter extends State<WalletReceiveInvoiceRouter> {
}

void _doCopy(String text) {
print("[WalletReceiveInvoiceRouter] _doCopy called with invoice: $text");
Clipboard.setData(ClipboardData(text: text)).then((_) {
// EasyLoading.showSuccess(I18n.of(context).Copy_success,
// dismissOnTap: true, duration: const Duration(seconds: 2));
print("[WalletReceiveInvoiceRouter] Clipboard.setData successful for invoice: $text");
EasyLoading.showSuccess(I18n.of(context).Copy_success,
dismissOnTap: true, duration: const Duration(seconds: 2));
}).catchError((error) {
print("[WalletReceiveInvoiceRouter] Clipboard.setData failed for invoice '$text'. Error: $error");
EasyLoading.showError("Failed to copy invoice: $error");
});
}

Expand Down
110 changes: 87 additions & 23 deletions lib/ui/enum_selector_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import '../utils/base.dart';
import '../utils/base_consts.dart';
import '../utils/router_util.dart';

class EnumSelectorComponent extends StatelessWidget {
class EnumSelectorComponent extends StatefulWidget {
final List<EnumObj> list;
final Widget Function(BuildContext, EnumObj)? enumItemBuild;

Widget Function(BuildContext, EnumObj)? enumItemBuild;

EnumSelectorComponent({
const EnumSelectorComponent({
super.key,
required this.list,
this.enumItemBuild,
});
Expand All @@ -25,45 +25,109 @@ class EnumSelectorComponent extends StatelessWidget {
);
}

@override
State<EnumSelectorComponent> createState() => _EnumSelectorComponentState();
}

class _EnumSelectorComponentState extends State<EnumSelectorComponent> {
late TextEditingController _searchController;
late List<EnumObj> _filteredList;

@override
void initState() {
super.initState();
_searchController = TextEditingController();
_filteredList = widget.list;
_searchController.addListener(_filterList);
}

@override
void dispose() {
_searchController.removeListener(_filterList);
_searchController.dispose();
super.dispose();
}

void _filterList() {
String query = _searchController.text.toLowerCase();
setState(() {
_filteredList = widget.list.where((enumObj) {
// Try to extract text from the widget if it's RichText or Text
String itemText = enumObj.value.toLowerCase();
if (enumObj.widget is RichText) {
final richText = enumObj.widget as RichText;
itemText = richText.text.toPlainText().toLowerCase();
} else if (enumObj.widget is Text) {
final textWidget = enumObj.widget as Text;
if (textWidget.data != null) {
itemText = textWidget.data!.toLowerCase();
}
}
return itemText.contains(query);
}).toList();
});
}

@override
Widget build(BuildContext context) {
var themeData = Theme.of(context);
Color cardColor = themeData.cardColor;
var maxHeight = MediaQuery.of(context).size.height;

List<Widget> widgets = [];
for (var i = 0; i < list.length; i++) {
var enumObj = list[i];
if (enumItemBuild != null) {
widgets.add(enumItemBuild!(context, enumObj));
for (var i = 0; i < _filteredList.length; i++) {
var enumObj = _filteredList[i];
if (widget.enumItemBuild != null) {
widgets.add(widget.enumItemBuild!(context, enumObj));
} else {
widgets.add(EnumSelectorItemComponent(
enumObj: enumObj,
isLast: i == list.length - 1,
isLast: i == _filteredList.length - 1,
));
}
}

Widget main = Container(
width: double.infinity,
padding: const EdgeInsets.only(
left: Base.BASE_PADDING,
right: Base.BASE_PADDING,
top: Base.BASE_PADDING_HALF,
bottom: Base.BASE_PADDING_HALF,
Widget searchField = Padding(
padding: const EdgeInsets.symmetric(horizontal: Base.BASE_PADDING, vertical: Base.BASE_PADDING_HALF),
child: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: 'Search currency...',
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
filled: true,
fillColor: themeData.scaffoldBackgroundColor, // Or another suitable color
),
),
);

Widget mainContent = Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(15)),
color: cardColor,
),
constraints: BoxConstraints(
maxHeight: maxHeight * 0.8,
maxHeight: maxHeight * 0.7, // Adjusted to make space for search bar
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: widgets,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
searchField,
Expanded(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: widgets.isEmpty && _searchController.text.isNotEmpty
? [Padding(padding: const EdgeInsets.all(16.0), child: Text("No currency found"))]
: widgets,
),
),
),
],
),
);

Expand All @@ -85,7 +149,7 @@ class EnumSelectorComponent extends StatelessWidget {
),
child: GestureDetector(
onTap: () {},
child: main,
child: mainContent,
),
alignment: Alignment.center,
),
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,18 @@ packages:
dependency: transitive
description:
name: build_resolvers
sha256: "99d3980049739a985cf9b21f30881f46db3ebc62c5b8d5e60e27440876b1ba1e"
sha256: b9e4fda21d846e192628e7a4f6deda6888c36b5b69ba02ff291a01fd529140f0
url: "https://pub.dev"
source: hosted
version: "2.4.3"
version: "2.4.4"
build_runner:
dependency: "direct dev"
description:
name: build_runner
sha256: "74691599a5bc750dc96a6b4bfd48f7d9d66453eab04c7f4063134800d6a5c573"
sha256: "058fe9dce1de7d69c4b84fada934df3e0153dd000758c4d65964d0166779aa99"
url: "https://pub.dev"
source: hosted
version: "2.4.14"
version: "2.4.15"
build_runner_core:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^5.0.0
build_runner: ^2.4.6
build_runner: ^2.4.15

dependency_overrides:
video_player_android: 2.8.2
Expand Down