mirror of
https://github.com/git-touch/git-touch
synced 2025-03-23 22:50:05 +01:00
feat: select branch with picker
This commit is contained in:
parent
cba1173e30
commit
ce00adf54c
@ -2,7 +2,6 @@ import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/widgets/picker.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class DialogOption<T> {
|
||||
@ -17,6 +16,26 @@ class AppThemeType {
|
||||
static const values = [AppThemeType.material, AppThemeType.cupertino];
|
||||
}
|
||||
|
||||
class PickerItem<T> {
|
||||
final T value;
|
||||
final String text;
|
||||
PickerItem(this.value, {@required this.text});
|
||||
}
|
||||
|
||||
class PickerGroupItem<T> {
|
||||
final T value;
|
||||
final List<PickerItem<T>> items;
|
||||
final Function(T value) onChange;
|
||||
final Function(T value) onClose;
|
||||
|
||||
PickerGroupItem({
|
||||
@required this.value,
|
||||
@required this.items,
|
||||
this.onChange,
|
||||
this.onClose,
|
||||
});
|
||||
}
|
||||
|
||||
class ThemeModel with ChangeNotifier {
|
||||
static const storageKey = 'theme';
|
||||
|
||||
@ -195,6 +214,8 @@ class ThemeModel with ChangeNotifier {
|
||||
|
||||
static Timer _debounce;
|
||||
|
||||
String _selectedItem;
|
||||
|
||||
showPicker(BuildContext context, PickerGroupItem<String> groupItem) async {
|
||||
switch (theme) {
|
||||
case AppThemeType.cupertino:
|
||||
@ -213,18 +234,25 @@ class ThemeModel with ChangeNotifier {
|
||||
.toList()
|
||||
.indexWhere((v) => v.value == groupItem.value)),
|
||||
onSelectedItemChanged: (index) {
|
||||
if (_debounce?.isActive ?? false) {
|
||||
_debounce.cancel();
|
||||
}
|
||||
_selectedItem = groupItem.items[index].value;
|
||||
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
groupItem.onChange(groupItem.items[index].value);
|
||||
});
|
||||
if (groupItem.onChange != null) {
|
||||
if (_debounce?.isActive ?? false) {
|
||||
_debounce.cancel();
|
||||
}
|
||||
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
groupItem.onChange(_selectedItem);
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
if (groupItem.onClose != null) {
|
||||
groupItem.onClose(_selectedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import 'package:git_touch/models/code.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/scaffolds/single.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/picker.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
@ -101,7 +101,7 @@ class RepositoryScreen extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
refs(first: 10, refPrefix: "refs/heads/") {
|
||||
refs(first: 100, refPrefix: "refs/heads/") {
|
||||
totalCount
|
||||
nodes {
|
||||
name
|
||||
@ -338,22 +338,24 @@ class RepositoryScreen extends StatelessWidget {
|
||||
var refs = payload['refs']['nodes'] as List;
|
||||
if (refs.length < 2) return;
|
||||
|
||||
// FIXME: Show all branches
|
||||
var result = await Provider.of<ThemeModel>(context)
|
||||
.showDialogOptions(
|
||||
await Provider.of<ThemeModel>(context).showPicker(
|
||||
context,
|
||||
PickerGroupItem(
|
||||
value: payload[branchInfoKey]['name'],
|
||||
items: refs
|
||||
.map((b) => PickerItem(b['name'] as String,
|
||||
text: (b['name'] as String)))
|
||||
.toList(),
|
||||
onClose: (result) {
|
||||
Provider.of<ThemeModel>(context)
|
||||
.pushReplacementRoute(
|
||||
context,
|
||||
refs
|
||||
.map((b) => DialogOption(
|
||||
value: b['name'] as String,
|
||||
widget: Text(b['name'] as String)))
|
||||
.toList());
|
||||
|
||||
if (result != null) {
|
||||
Provider.of<ThemeModel>(context).pushReplacementRoute(
|
||||
context,
|
||||
(_) => RepositoryScreen(owner, name,
|
||||
branch: result));
|
||||
}
|
||||
(_) => RepositoryScreen(owner, name,
|
||||
branch: result),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -1,20 +0,0 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PickerItem<T> {
|
||||
final T value;
|
||||
final String text;
|
||||
PickerItem(this.value, {@required this.text});
|
||||
}
|
||||
|
||||
class PickerGroupItem<T> {
|
||||
final T value;
|
||||
final List<PickerItem<T>> items;
|
||||
final Function(T value) onChange;
|
||||
|
||||
PickerGroupItem({
|
||||
@required this.value,
|
||||
@required this.items,
|
||||
@required this.onChange,
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user