Skip to content

Commit

Permalink
Improved follow download live feature in example app
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup committed Oct 22, 2023
1 parent 6810bfa commit 6309659
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Also:
* Created automated tests for tile generation
* Improved & simplified example application
* Removed update mechanism
* Added user location tracking
* Added tile-by-tile download following

## [8.0.1] - 2023/07/29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import 'package:provider/provider.dart';

import '../state/configure_download_provider.dart';

class NumericalInputRow extends StatelessWidget {
class NumericalInputRow extends StatefulWidget {
const NumericalInputRow({
super.key,
required this.label,
required this.suffixText,
required this.value,
required this.min,
required this.max,
this.maxEligibleTilesPreview,
required this.onChanged,
});

Expand All @@ -20,54 +21,87 @@ class NumericalInputRow extends StatelessWidget {
final int Function(ConfigureDownloadProvider provider) value;
final int min;
final int? max;
final int? maxEligibleTilesPreview;
final void Function(ConfigureDownloadProvider provider, int value) onChanged;

@override
Widget build(BuildContext context) {
final currentValue = context.select<ConfigureDownloadProvider, int>(value);
State<NumericalInputRow> createState() => _NumericalInputRowState();
}

class _NumericalInputRowState extends State<NumericalInputRow> {
TextEditingController? tec;

@override
Widget build(BuildContext context) =>
Selector<ConfigureDownloadProvider, int>(
selector: (context, provider) => widget.value(provider),
builder: (context, currentValue, _) {
tec ??= TextEditingController(text: currentValue.toString());

return Row(
children: [
Text(label),
const Spacer(),
if (max != null) ...[
Tooltip(
message: currentValue == max ? 'Limited in the example app' : '',
child: Icon(
Icons.lock,
color: currentValue == max
? Colors.amber
: Colors.white.withOpacity(0.2),
),
),
const SizedBox(width: 16),
],
IntrinsicWidth(
child: TextFormField(
initialValue: currentValue.toString(),
textAlign: TextAlign.end,
keyboardType: TextInputType.number,
decoration: InputDecoration(
isDense: true,
counterText: '',
suffixText: ' $suffixText',
),
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
_NumericalRangeFormatter(
min: min,
max: max ?? 9223372036854775807,
return Row(
children: [
Text(widget.label),
const Spacer(),
if (widget.maxEligibleTilesPreview != null) ...[
IconButton(
icon: const Icon(Icons.visibility),
disabledColor: Colors.green,
tooltip: currentValue > widget.maxEligibleTilesPreview!
? 'Tap to enable following download live'
: 'Eligible to follow download live',
onPressed: currentValue > widget.maxEligibleTilesPreview!
? () {
widget.onChanged(
context.read<ConfigureDownloadProvider>(),
widget.maxEligibleTilesPreview!,
);
tec!.text = widget.maxEligibleTilesPreview.toString();
}
: null,
),
const SizedBox(width: 8),
],
if (widget.max != null) ...[
Tooltip(
message: currentValue == widget.max
? 'Limited in the example app'
: '',
child: Icon(
Icons.lock,
color: currentValue == widget.max
? Colors.amber
: Colors.white.withOpacity(0.2),
),
),
const SizedBox(width: 16),
],
IntrinsicWidth(
child: TextFormField(
controller: tec,
textAlign: TextAlign.end,
keyboardType: TextInputType.number,
decoration: InputDecoration(
isDense: true,
counterText: '',
suffixText: ' ${widget.suffixText}',
),
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
_NumericalRangeFormatter(
min: widget.min,
max: widget.max ?? 9223372036854775807,
),
],
onChanged: (newVal) => widget.onChanged(
context.read<ConfigureDownloadProvider>(),
int.tryParse(newVal) ?? currentValue,
),
),
),
],
onChanged: (newVal) => onChanged(
context.read<ConfigureDownloadProvider>(),
int.tryParse(newVal) ?? currentValue,
),
),
),
],
);
}
);
},
);
}

class _NumericalRangeFormatter extends TextInputFormatter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ class ConfigureDownloadPopup extends StatelessWidget {
label: 'Rate Limit',
suffixText: 'max. tps',
value: (provider) => provider.rateLimit,
min: 5,
min: 1,
max: 500,
maxEligibleTilesPreview: 20,
onChanged: (provider, value) =>
provider.rateLimit = value,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import 'package:flutter/foundation.dart';

class ConfigureDownloadProvider extends ChangeNotifier {
int _parallelThreads = 5;
static const defaultValues = {
'parallelThreads': 5,
'rateLimit': 200,
'maxBufferLength': 500,
};

int _parallelThreads = defaultValues['parallelThreads']!;
int get parallelThreads => _parallelThreads;
set parallelThreads(int newNum) {
_parallelThreads = newNum;
notifyListeners();
}

int _rateLimit = 200;
int _rateLimit = defaultValues['rateLimit']!;
int get rateLimit => _rateLimit;
set rateLimit(int newNum) {
_rateLimit = newNum;
notifyListeners();
}

int _maxBufferLength = 500;
int _maxBufferLength = defaultValues['maxBufferLength']!;
int get maxBufferLength => _maxBufferLength;
set maxBufferLength(int newNum) {
_maxBufferLength = newNum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class QuitTilesPreviewIndicator extends StatelessWidget {
const SizedBox.square(dimension: 6),
RotatedBox(
quarterTurns: isNarrow ? 1 : 0,
child: const Icon(Icons.disabled_visible, size: 32),
child: const Icon(Icons.visibility_off, size: 32),
),
],
),
Expand Down

0 comments on commit 6309659

Please sign in to comment.