git-touch-android-ios-app/lib/screens/search.dart

79 lines
1.9 KiB
Dart
Raw Normal View History

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';
import 'package:git_touch/models/theme.dart';
import 'package:provider/provider.dart';
2019-02-02 17:28:51 +01:00
import '../providers/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
var data = await SettingsProvider.of(context).query('''
{
search(first: $pageSize, type: REPOSITORY, query: "$value") {
nodes {
... on Repository {
$repoChunk
}
}
}
}
''');
repos = data['search']['nodes'];
} finally {
setState(() {
loading = false;
});
}
}
Widget _buildInput() {
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: () {
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
}