mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-13 22:53:45 +08:00
RepoSelector: Auto select exact matching item when the user types it in
This commit is contained in:
@ -2,6 +2,8 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
typedef OAuthCallback = void Function(GitHostException);
|
||||
|
||||
abstract class GitHost {
|
||||
@ -79,8 +81,19 @@ class GitHostRepo {
|
||||
|
||||
@override
|
||||
String toString() => toJson().toString();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is GitHostRepo &&
|
||||
runtimeType == other.runtimeType &&
|
||||
_mapEquals(toJson(), other.toJson());
|
||||
@override
|
||||
int get hashCode => toJson().hashCode;
|
||||
}
|
||||
|
||||
var _mapEquals = (const MapEquality()).equals;
|
||||
|
||||
class GitHostException implements Exception {
|
||||
static const OAuthFailed = GitHostException("OAuthFailed");
|
||||
static const MissingAccessCode = GitHostException("MissingAccessCode");
|
||||
|
@ -50,10 +50,27 @@ class GitHostSetupRepoSelectorState extends State<GitHostSetupRepoSelector> {
|
||||
super.initState();
|
||||
|
||||
_textController.addListener(() {
|
||||
var q = _textController.text.toLowerCase();
|
||||
if (q.isEmpty) {
|
||||
setState(() {
|
||||
selectedRepo = null;
|
||||
createRepo = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
var repoIndex = repos.indexWhere((r) =>
|
||||
r.name.toLowerCase() == q && r.username == widget.userInfo.username);
|
||||
if (repoIndex == -1) {
|
||||
setState(() {
|
||||
selectedRepo = null;
|
||||
createRepo = false;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
selectedRepo = repos[repoIndex];
|
||||
createRepo = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
_initStateAysnc();
|
||||
}
|
||||
@ -336,13 +353,18 @@ class _RepoTile extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
var tile = ListTile(
|
||||
title: title,
|
||||
trailing: _SmartDateTime(repo.updatedAt, textTheme.caption),
|
||||
selected: selected,
|
||||
contentPadding: const EdgeInsets.all(0.0),
|
||||
onTap: onTap,
|
||||
);
|
||||
|
||||
return Ink(
|
||||
color: selected ? Theme.of(context).highlightColor : Colors.transparent,
|
||||
child: tile,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user