2019-02-02 17:28:51 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-01-23 12:52:51 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:git_touch/models/settings.dart';
|
2019-02-10 06:42:02 +01:00
|
|
|
import '../scaffolds/simple.dart';
|
|
|
|
import '../utils/utils.dart';
|
|
|
|
import '../widgets/repo_item.dart';
|
|
|
|
import '../widgets/loading.dart';
|
2019-01-23 12:52:51 +01:00
|
|
|
|
2019-02-02 17:28:51 +01:00
|
|
|
class SearchScreen extends StatefulWidget {
|
2019-01-23 12:52:51 +01:00
|
|
|
@override
|
2019-02-02 17:28:51 +01:00
|
|
|
_SearchScreenState createState() => _SearchScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SearchScreenState extends State<SearchScreen> {
|
|
|
|
int active = 0;
|
2019-02-10 06:42:02 +01:00
|
|
|
bool loading = false;
|
|
|
|
List repos = [];
|
2019-01-23 12:52:51 +01:00
|
|
|
|
2019-02-10 06:42:02 +01:00
|
|
|
_onSubmitted(String value) async {
|
|
|
|
setState(() {
|
|
|
|
loading = true;
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
// TODO: search other types
|
2019-09-08 14:07:35 +02:00
|
|
|
var data = await Provider.of<SettingsModel>(context).query('''
|
2019-02-10 06:42:02 +01:00
|
|
|
{
|
|
|
|
search(first: $pageSize, type: REPOSITORY, query: "$value") {
|
|
|
|
nodes {
|
|
|
|
... on Repository {
|
|
|
|
$repoChunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
|
|
|
repos = data['search']['nodes'];
|
|
|
|
} finally {
|
|
|
|
setState(() {
|
|
|
|
loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildInput() {
|
2019-09-02 15:52:32 +02:00
|
|
|
switch (Provider.of<ThemeModel>(context).theme) {
|
2019-02-07 07:35:19 +01:00
|
|
|
case ThemeMap.cupertino:
|
2019-02-10 06:42:02 +01:00
|
|
|
return CupertinoTextField(
|
|
|
|
// padding: EdgeInsets.all(10),
|
|
|
|
placeholder: 'Type to search',
|
|
|
|
clearButtonMode: OverlayVisibilityMode.editing,
|
|
|
|
onSubmitted: _onSubmitted,
|
2019-02-02 17:28:51 +01:00
|
|
|
);
|
|
|
|
default:
|
2019-02-10 06:42:02 +01:00
|
|
|
return TextField(onSubmitted: _onSubmitted);
|
2019-02-02 17:28:51 +01:00
|
|
|
}
|
2019-01-23 12:52:51 +01:00
|
|
|
}
|
2019-02-10 06:42:02 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SimpleScaffold(
|
|
|
|
title: Text('Search GitHub Repositories'),
|
|
|
|
bodyBuilder: () {
|
2019-09-02 15:52:32 +02:00
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(padding: EdgeInsets.all(8), child: _buildInput()),
|
|
|
|
loading
|
|
|
|
? Loading()
|
|
|
|
: Column(
|
|
|
|
children: repos.map((repo) => RepoItem(repo)).toList(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
2019-02-10 06:42:02 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2019-01-23 12:52:51 +01:00
|
|
|
}
|