37 lines
1.0 KiB
Dart
37 lines
1.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../model/bookmark.dart';
|
|
import '../../service/notifying.dart';
|
|
import '../../service/url_launcher.dart';
|
|
|
|
class SearchResultsWidget extends StatelessWidget {
|
|
const SearchResultsWidget({super.key, required this.bookmarks});
|
|
|
|
final Iterable<Bookmark> bookmarks;
|
|
|
|
Widget bookmarkListItemBuilder(BuildContext context, int index) {
|
|
final bookmark = bookmarks.elementAt(index);
|
|
return ListTile(
|
|
title: Text(bookmark.name),
|
|
onTap: () => launchUrlFromString(bookmark.link).then((errorCode) {
|
|
if (context.mounted && errorCode != UrlLaunchErrorCode.none) {
|
|
Notifying.showUrlErrorSnackbar(context, errorCode);
|
|
} else if (context.mounted) {
|
|
Navigator.of(context).pop();
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (bookmarks.isNotEmpty) {
|
|
return ListView.builder(
|
|
itemBuilder: bookmarkListItemBuilder,
|
|
itemCount: bookmarks.length,
|
|
);
|
|
}
|
|
return Center(child: Text('Start searching'));
|
|
}
|
|
}
|