mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 19:57:42 +01:00
feat: add search screen
This commit is contained in:
parent
5f94c0f80f
commit
8e86e85b55
@ -1,6 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import '../providers/settings.dart';
|
import '../providers/settings.dart';
|
||||||
|
import '../scaffolds/simple.dart';
|
||||||
|
import '../utils/utils.dart';
|
||||||
|
import '../widgets/repo_item.dart';
|
||||||
|
import '../widgets/loading.dart';
|
||||||
|
|
||||||
class SearchScreen extends StatefulWidget {
|
class SearchScreen extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -9,59 +13,62 @@ class SearchScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _SearchScreenState extends State<SearchScreen> {
|
class _SearchScreenState extends State<SearchScreen> {
|
||||||
int active = 0;
|
int active = 0;
|
||||||
List users = [];
|
bool loading = false;
|
||||||
|
List repos = [];
|
||||||
|
|
||||||
@override
|
_onSubmitted(String value) async {
|
||||||
Widget build(BuildContext context) {
|
setState(() {
|
||||||
switch (SettingsProvider.of(context).theme) {
|
loading = true;
|
||||||
case ThemeMap.cupertino:
|
});
|
||||||
return CupertinoPageScaffold(
|
try {
|
||||||
navigationBar: CupertinoNavigationBar(
|
// TODO: search other types
|
||||||
middle: CupertinoTextField(
|
var data = await SettingsProvider.of(context).query('''
|
||||||
placeholder: 'Type to search',
|
{
|
||||||
onChanged: (String value) {
|
search(first: $pageSize, type: REPOSITORY, query: "$value") {
|
||||||
//
|
nodes {
|
||||||
},
|
... on Repository {
|
||||||
onSubmitted: (String value) {
|
$repoChunk
|
||||||
//
|
}
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: SafeArea(
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
CupertinoSegmentedControl(
|
|
||||||
children: {0: Text('Repos'), 1: Text('Users')},
|
|
||||||
onValueChanged: (int value) {
|
|
||||||
//
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ListView.builder(
|
|
||||||
shrinkWrap: true,
|
|
||||||
itemCount: users.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
var user = users[index];
|
|
||||||
return Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Image.network(user['avatarUrl']),
|
|
||||||
Text(user['login']),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(title: Text('Search')),
|
|
||||||
body: ListView.builder(
|
|
||||||
itemCount: users.length,
|
|
||||||
itemBuilder: (context, index) => Text(''),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
repos = data['search']['nodes'];
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
loading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildInput() {
|
||||||
|
switch (SettingsProvider.of(context).theme) {
|
||||||
|
case ThemeMap.cupertino:
|
||||||
|
return CupertinoTextField(
|
||||||
|
// padding: EdgeInsets.all(10),
|
||||||
|
placeholder: 'Type to search',
|
||||||
|
clearButtonMode: OverlayVisibilityMode.editing,
|
||||||
|
onSubmitted: _onSubmitted,
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return TextField(onSubmitted: _onSubmitted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SimpleScaffold(
|
||||||
|
title: Text('Search GitHub Repositories'),
|
||||||
|
bodyBuilder: () {
|
||||||
|
return Column(children: <Widget>[
|
||||||
|
Container(padding: EdgeInsets.all(8), child: _buildInput()),
|
||||||
|
loading
|
||||||
|
? Loading()
|
||||||
|
: Column(
|
||||||
|
children: repos.map((repo) => RepoItem(repo)).toList(),
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user