blob: b77db6c14cc006e9306a4434f6cafa64fdc45e63 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
const MethodChannel _kChannel =
MethodChannel('plugins.flutter.io/shared_preferences_android');
/// The Android implementation of [SharedPreferencesStorePlatform].
///
/// This class implements the `package:shared_preferences` functionality for Android.
class SharedPreferencesAndroid extends SharedPreferencesStorePlatform {
/// Registers this class as the default instance of [SharedPreferencesStorePlatform].
static void registerWith() {
SharedPreferencesStorePlatform.instance = SharedPreferencesAndroid();
}
static const String _defaultPrefix = 'flutter.';
@override
Future<bool> remove(String key) async {
return (await _kChannel.invokeMethod<bool>(
'remove',
<String, dynamic>{'key': key},
))!;
}
@override
Future<bool> setValue(String valueType, String key, Object value) async {
return (await _kChannel.invokeMethod<bool>(
'set$valueType',
<String, dynamic>{'key': key, 'value': value},
))!;
}
@override
Future<bool> clear() async {
return clearWithPrefix(_defaultPrefix);
}
@override
Future<bool> clearWithPrefix(String prefix) async {
return (await _kChannel.invokeMethod<bool>(
'clearWithPrefix',
<String, dynamic>{'prefix': prefix},
))!;
}
@override
Future<Map<String, Object>> getAll() async {
return getAllWithPrefix(_defaultPrefix);
}
@override
Future<Map<String, Object>> getAllWithPrefix(String prefix) async {
return (await _kChannel.invokeMapMethod<String, Object>(
'getAllWithPrefix',
<String, dynamic>{'prefix': prefix},
)) ??
<String, Object>{};
}
}