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

80 lines
2.0 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';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.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() {
switch (Provider.of<ThemeModel>(context).theme) {
2019-09-15 11:36:09 +02:00
case AppThemeMap.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(
2019-09-11 13:59:47 +02:00
title: AppBarTitle('Search GitHub Repositories'),
2019-02-10 06:42:02 +01:00
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
}