-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 13 additions & 42 deletions
55
lib/tools/encoders_decoders/uri_encoder_decoder/uri_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,16 @@ | ||
import 'package:alga/utils/clipboard_util.dart'; | ||
import 'package:flutter/material.dart'; | ||
part of './uri_encoder_decoder.dart'; | ||
|
||
class UriProvider extends ChangeNotifier { | ||
final inputController = TextEditingController(); | ||
String _uriResult = ''; | ||
String get uriResult => _uriResult; | ||
set uriResult(String state) { | ||
_uriResult = state; | ||
notifyListeners(); | ||
} | ||
final _input = StateProvider.autoDispose<TextEditingController>((ref) { | ||
final controller = TextEditingController(); | ||
ref.onDispose(controller.dispose); | ||
return controller; | ||
}); | ||
|
||
bool _isEncode = true; | ||
bool get isEncode => _isEncode; | ||
set isEncode(bool state) { | ||
_isEncode = state; | ||
notifyListeners(); | ||
} | ||
final _isEncode = StateProvider.autoDispose((ref) => true); | ||
|
||
clear() { | ||
inputController.clear(); | ||
uriResult = ''; | ||
} | ||
|
||
paste() async { | ||
inputController.text = await ClipboardUtil.paste(); | ||
convert(); | ||
} | ||
|
||
copy() async { | ||
await ClipboardUtil.copy(uriResult); | ||
} | ||
|
||
convert() { | ||
uriResult = _isEncode | ||
? Uri.encodeFull(inputController.text) | ||
: Uri.decodeFull(inputController.text); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
inputController.dispose(); | ||
super.dispose(); | ||
} | ||
} | ||
final _result = StateProvider.autoDispose<String>((ref) { | ||
final isEncode = ref.watch(_isEncode); | ||
final text = ref.watch(_input).text; | ||
if (text.isEmpty) return ''; | ||
return isEncode ? Uri.encodeFull(text) : Uri.decodeFull(text); | ||
}); |