[英]How can we use service locator in custom flutter library or package?
創建一個新Interface
作為您要從此包中使用的方法的合同。
然后,在一個新的類中實現這個接口,並用這個包的實現將包封裝在這個類中。
最后,在這個類中使用你的服務定位器,就像你對普通類一樣。
前任。
abstract class Encryptor{
Future<String> encrypt(String input);
Future<String> decrypt(String input);
}
class EncryptorImpl implement Encryptor{
Future<String> encrypt(String input){
final result = await encrypt.encrypt("myKey", input);
return result;
}
Future<String> decrypt(String input){
//same!!
.
.
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.