1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-16 10:20:55 +01:00

refactor: search screen

This commit is contained in:
Rongjian Zhang 2019-09-29 22:10:15 +08:00
parent be1221b741
commit b93d8313f9
3 changed files with 84 additions and 50 deletions

View File

@ -117,12 +117,8 @@ class _HomeState extends State<Home> {
Widget build(BuildContext context) {
var settings = Provider.of<AuthModel>(context);
var themData = ThemeData(
// primaryColor: HSLColor.fromColor(Palette.primary)
// .withLightness(0.3)
// .toColor(),
// primaryColor: Color(0xff333333),
primaryColor: PrimerColors.gray900,
accentColor: PrimerColors.gray900,
primaryColor: PrimerColors.white,
accentColor: PrimerColors.blue500,
);
// TODO:

View File

@ -1,10 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/tab.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/scaffolds/utils.dart';
import 'package:git_touch/widgets/issue_item.dart';
import 'package:git_touch/widgets/loading.dart';
import 'package:git_touch/widgets/user_item.dart';
import 'package:primer/primer.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/models/auth.dart';
import '../utils/utils.dart';
@ -93,21 +94,42 @@ class _SearchScreenState extends State<SearchScreen> {
Widget _buildInput() {
switch (Provider.of<ThemeModel>(context).theme) {
case AppThemeType.cupertino:
return CupertinoTextField(
controller: _controller,
// padding: EdgeInsets.all(10),
placeholder: 'Type to search',
clearButtonMode: OverlayVisibilityMode.editing,
onSubmitted: (_) => _query(),
return Container(
color: Colors.white,
child: CupertinoTextField(
prefix: Row(
children: <Widget>[
SizedBox(width: 8),
Icon(Octicons.search, size: 20, color: PrimerColors.gray400),
],
),
placeholder: 'Search',
clearButtonMode: OverlayVisibilityMode.editing,
textInputAction: TextInputAction.go,
onSubmitted: (_) => _query(),
controller: _controller,
),
);
default:
return TextField(
textInputAction: TextInputAction.go,
onSubmitted: (_) => _query(),
controller: _controller,
);
}
}
_onTabSwitch(int index) {
setState(() {
_activeTab = index;
});
if (_payloads[_activeTab].isEmpty) {
_query();
}
}
static const tabs = ['Repositories', 'Users', 'Issues'];
Widget _buildItem(data) {
switch (_activeTab) {
case 0:
@ -126,25 +148,50 @@ class _SearchScreenState extends State<SearchScreen> {
@override
Widget build(BuildContext context) {
return TabScaffold(
title: AppBarTitle('Search GitHub Repositories'),
body: Column(
children: <Widget>[
Container(padding: EdgeInsets.all(8), child: _buildInput()),
Column(children: _payloads[_activeTab].map(_buildItem).toList())
],
final theme = Provider.of<ThemeModel>(context).theme;
final scaffold = CommonScaffold(
title: _buildInput(),
body: SingleChildScrollView(
child: _loading
? Loading()
: Column(
children: [
if (theme == AppThemeType.cupertino)
Center(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: CupertinoSegmentedControl(
groupValue: _activeTab,
onValueChanged: _onTabSwitch,
children: tabs.asMap().map((key, text) => MapEntry(
key,
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8),
child:
Text(text, style: TextStyle(fontSize: 14)),
))),
),
),
),
..._payloads[_activeTab].map(_buildItem).toList(),
],
),
),
bottom: TabBar(
onTap: _onTabSwitch,
tabs: tabs.map((text) => Tab(text: text.toUpperCase())).toList(),
),
activeTab: _activeTab,
onRefresh: _query,
onTabSwitch: (int index) {
setState(() {
_activeTab = index;
});
if (_payloads[_activeTab].isEmpty) {
_query();
}
},
tabs: ['Repositories', 'Users', 'Issues'],
);
if (theme == AppThemeType.material) {
return DefaultTabController(
length: tabs.length,
child: scaffold,
);
} else {
return scaffold;
}
}
}

View File

@ -9,34 +9,25 @@ class Loading extends StatelessWidget {
Loading({this.more = false});
Widget _buildIndicator(BuildContext context) {
// return Image.asset('images/loading.webp');
switch (Provider.of<ThemeModel>(context).theme) {
case AppThemeType.cupertino:
return CupertinoActivityIndicator(radius: 12);
default:
return Center(
child: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(),
),
return SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(),
);
}
}
@override
Widget build(BuildContext context) {
if (more) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 20),
return Center(
child: Padding(
padding: EdgeInsets.symmetric(vertical: more ? 20 : 100),
child: _buildIndicator(context),
);
} else {
return Padding(
padding: EdgeInsets.symmetric(vertical: 50),
child: _buildIndicator(context),
);
}
),
);
}
}