|
| 1 | +import 'package:desktop_adb_file_browser/riverpod/settings.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter/services.dart'; |
| 4 | +import 'package:flutter_riverpod/flutter_riverpod.dart'; |
| 5 | + |
| 6 | +class SettingsPage extends ConsumerStatefulWidget { |
| 7 | + const SettingsPage({super.key}); |
| 8 | + |
| 9 | + @override |
| 10 | + ConsumerState<ConsumerStatefulWidget> createState() => _SettingsPageState(); |
| 11 | +} |
| 12 | + |
| 13 | +class _SettingsPageState extends ConsumerState<SettingsPage> { |
| 14 | + @override |
| 15 | + Widget build(BuildContext context) { |
| 16 | + final settings = ref.watch(settingsProvider); |
| 17 | + var multipleADBLimit = SizedBox( |
| 18 | + width: 200, |
| 19 | + child: TextFormField( |
| 20 | + initialValue: settings.multipleAdbInstances.toString(), |
| 21 | + keyboardType: const TextInputType.numberWithOptions( |
| 22 | + signed: false, decimal: false), |
| 23 | + inputFormatters: <TextInputFormatter>[ |
| 24 | + FilteringTextInputFormatter.digitsOnly |
| 25 | + ], // Only numbers can be entered |
| 26 | + decoration: |
| 27 | + const InputDecoration(label: Text("Multiple ADB Instance Limit")), |
| 28 | + onChanged: (v) => updateSettings( |
| 29 | + settings.copyWith( |
| 30 | + multipleAdbInstances: |
| 31 | + (double.tryParse(v) ?? settings.multipleAdbInstances) |
| 32 | + .toInt()), |
| 33 | + ), |
| 34 | + ), |
| 35 | + ); |
| 36 | + return Scaffold( |
| 37 | + appBar: AppBar( |
| 38 | + title: const Text("Settings"), |
| 39 | + ), |
| 40 | + body: Padding( |
| 41 | + padding: const EdgeInsets.all(16.0), |
| 42 | + child: Column( |
| 43 | + children: [ |
| 44 | + Tooltip( |
| 45 | + message: |
| 46 | + "Specifies the limit of ADB instances that can run simultaneously", |
| 47 | + waitDuration: const Duration(milliseconds: 500), |
| 48 | + child: multipleADBLimit, |
| 49 | + ) |
| 50 | + ], |
| 51 | + ), |
| 52 | + ), |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + void updateSettings(SettingsData settings) { |
| 57 | + var notifier = ref.read(settingsProvider.notifier); |
| 58 | + notifier.update(settings); |
| 59 | + } |
| 60 | +} |
0 commit comments