ente/lib/ui/search_page.dart

80 lines
2.3 KiB
Dart
Raw Normal View History

2020-04-05 08:31:01 +00:00
import 'package:flutter/material.dart';
2020-10-03 17:56:18 +00:00
import 'package:photos/services/face_search_service.dart';
2020-05-01 18:20:12 +00:00
import 'package:photos/models/face.dart';
import 'package:photos/ui/circular_network_image_widget.dart';
import 'package:photos/ui/face_search_results_page.dart';
2020-06-02 11:32:35 +00:00
import 'package:photos/ui/loading_widget.dart';
2020-06-06 11:38:11 +00:00
import 'package:photos/ui/location_search_widget.dart';
2020-04-05 08:31:01 +00:00
2020-06-03 13:18:55 +00:00
class SearchPage extends StatefulWidget {
@override
_SearchPageState createState() => _SearchPageState();
}
class _SearchPageState extends State<SearchPage> {
2020-10-03 17:56:18 +00:00
final FaceSearchService _faceSearchManager = FaceSearchService.instance;
2020-06-03 13:18:55 +00:00
String _searchString = "";
2020-04-05 08:31:01 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2020-06-06 11:38:11 +00:00
title: LocationSearchWidget(),
2020-04-05 08:31:01 +00:00
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
)
],
),
2020-04-05 12:22:38 +00:00
body: Container(
2020-06-03 13:18:55 +00:00
child: _searchString.isEmpty ? _getSearchSuggestions() : Container(),
2020-04-05 12:22:38 +00:00
),
);
}
Widget _getSearchSuggestions() {
return FutureBuilder<List<Face>>(
future: _faceSearchManager.getFaces(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Container(
height: 60,
margin: EdgeInsets.only(top: 4, left: 4),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return _buildItem(context, snapshot.data[index]);
}),
);
2020-06-02 11:32:35 +00:00
} else if (snapshot.hasError) {
return Center(child: Text("Error: " + snapshot.error.toString()));
2020-04-05 12:22:38 +00:00
} else {
2020-06-02 11:32:35 +00:00
return Center(child: loadWidget);
2020-04-05 12:22:38 +00:00
}
},
2020-04-05 08:31:01 +00:00
);
}
2020-04-05 12:22:38 +00:00
Widget _buildItem(BuildContext context, Face face) {
2020-04-05 14:00:44 +00:00
return GestureDetector(
onTap: () {
_routeToSearchResults(face, context);
},
child: CircularNetworkImageWidget(face.getThumbnailUrl(), 60),
2020-04-05 14:00:44 +00:00
);
}
void _routeToSearchResults(Face face, BuildContext context) {
2020-06-03 14:11:34 +00:00
final page = FaceSearchResultsPage(face);
2020-04-05 14:00:44 +00:00
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return page;
},
),
);
2020-04-05 12:22:38 +00:00
}
2020-04-05 08:31:01 +00:00
}