Skip to content

Commit

Permalink
Merge pull request #53 from ente-io/search_ux
Browse files Browse the repository at this point in the history
Improve UX for search
  • Loading branch information
vishnukvmd authored Feb 6, 2023
2 parents 4f7b6e9 + 120fee3 commit bad2baf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 41 deletions.
67 changes: 27 additions & 40 deletions lib/ui/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import 'package:ente_auth/ui/code_widget.dart';
import 'package:ente_auth/ui/common/loading_widget.dart';
import 'package:ente_auth/ui/scanner_page.dart';
import 'package:ente_auth/ui/settings_page.dart';
import 'package:ente_auth/utils/device_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:move_to_background/move_to_background.dart';
Expand Down Expand Up @@ -64,7 +63,7 @@ class _HomePageState extends State<HomePage> {
}

void _applyFiltering() {
if (_searchText.isNotEmpty) {
if (_searchText.isNotEmpty && _showSearchBox) {
final String val = _searchText.toLowerCase();
_filteredCodes = _codes
.where(
Expand Down Expand Up @@ -148,22 +147,36 @@ class _HomePageState extends State<HomePage> {
),
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Text('ente Authenticator'),
title: !_showSearchBox
? const Text('ente Authenticator')
: TextField(
autofocus: _searchText.isEmpty,
controller: _textController,
onChanged: (val) {
_searchText = val;
_applyFiltering();
},
decoration: const InputDecoration(
hintText: 'Search...',
border: InputBorder.none,
),
),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.search),
icon: _showSearchBox
? const Icon(Icons.clear)
: const Icon(Icons.search),
tooltip: 'Search',
onPressed: () {
setState(
() {
_showSearchBox = !_showSearchBox;
if (!_showSearchBox) {
_searchText = "";
_applyFiltering();
} else if (_textController.text.isNotEmpty) {
_textController.clear();
} else {
_searchText = _textController.text;
_applyFiltering();
}
_applyFiltering();
},
);
},
Expand Down Expand Up @@ -200,42 +213,16 @@ class _HomePageState extends State<HomePage> {
} else if (_showSearchBox) {
return Column(
children: [
Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: TextField(
autofocus: _searchText.isEmpty,
controller: _textController,
onChanged: (val) {
_searchText = val;
_applyFiltering();
},
decoration: InputDecoration(
// prefixIcon: const Icon(Icons.search),
suffixIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
_textController.clear();
_searchText = "";
_applyFiltering();
},
),
hintText: 'Search...',
border: InputBorder.none,
),
),
),
),
_filteredCodes.isNotEmpty
? Expanded(
child: ListView.builder(
Expanded(
child: _filteredCodes.isNotEmpty
? ListView.builder(
itemBuilder: ((context, index) {
return CodeWidget(_filteredCodes[index]);
}),
itemCount: _filteredCodes.length,
),
)
: (const Text("No result")),
)
: const Center(child: (Text("No result"))),
),
],
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ente_auth
description: ente two-factor authenticator
version: 1.0.27+27
version: 1.0.28+28
publish_to: none

environment:
Expand Down

0 comments on commit bad2baf

Please sign in to comment.