1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 02:38:39 +01:00
git-touch-android-ios-app/lib/screens/search.dart
2019-09-25 14:24:20 +08:00

78 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/models/settings.dart';
import '../scaffolds/simple.dart';
import '../utils/utils.dart';
import 'package:git_touch/widgets/repository_item.dart';
import '../widgets/loading.dart';
class SearchScreen extends StatefulWidget {
@override
_SearchScreenState createState() => _SearchScreenState();
}
class _SearchScreenState extends State<SearchScreen> {
int active = 0;
bool loading = false;
List repos = [];
_onSubmitted(String value) async {
setState(() {
loading = true;
});
try {
// TODO: search other types
var data = await Provider.of<SettingsModel>(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) {
case AppThemeType.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: AppBarTitle('Search GitHub Repositories'),
child: Column(
children: <Widget>[
Container(padding: EdgeInsets.all(8), child: _buildInput()),
loading
? Loading()
: Column(
children: repos.map((repo) => RepositoryItem(repo)).toList(),
)
],
),
);
}
}