shared_preferences: update for official packages/shared_preferences 2.2.0 (#69)
Signed-off-by: Hidenori Matsubayashi <[email protected]>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2021 Sony Group Corporation. All rights reserved.
|
||||
// Copyright 2023 Sony Group Corporation. All rights reserved.
|
||||
// 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.
|
||||
@@ -11,13 +11,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences_elinux/shared_preferences_elinux.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
return const MaterialApp(
|
||||
title: 'SharedPreferences Demo',
|
||||
home: SharedPreferencesDemo(),
|
||||
);
|
||||
@@ -25,18 +27,18 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
class SharedPreferencesDemo extends StatefulWidget {
|
||||
SharedPreferencesDemo({Key? key}) : super(key: key);
|
||||
const SharedPreferencesDemo({super.key});
|
||||
|
||||
@override
|
||||
SharedPreferencesDemoState createState() => SharedPreferencesDemoState();
|
||||
}
|
||||
|
||||
class SharedPreferencesDemoState extends State<SharedPreferencesDemo> {
|
||||
final prefs = SharedPreferencesELinux.instance;
|
||||
final SharedPreferencesELinux prefs = SharedPreferencesELinux();
|
||||
late Future<int> _counter;
|
||||
|
||||
Future<void> _incrementCounter() async {
|
||||
final values = await prefs.getAll();
|
||||
final Map<String, Object> values = await prefs.getAll();
|
||||
final int counter = (values['counter'] as int? ?? 0) + 1;
|
||||
|
||||
setState(() {
|
||||
@@ -50,7 +52,7 @@ class SharedPreferencesDemoState extends State<SharedPreferencesDemo> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_counter = prefs.getAll().then((Map<String, Object> values) {
|
||||
return (values['counter'] as int? ?? 0);
|
||||
return values['counter'] as int? ?? 0;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,16 +60,18 @@ class SharedPreferencesDemoState extends State<SharedPreferencesDemo> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("SharedPreferences Demo"),
|
||||
title: const Text('SharedPreferences Demo'),
|
||||
),
|
||||
body: Center(
|
||||
child: FutureBuilder<int>(
|
||||
future: _counter,
|
||||
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
|
||||
switch (snapshot.connectionState) {
|
||||
case ConnectionState.none:
|
||||
case ConnectionState.waiting:
|
||||
return const CircularProgressIndicator();
|
||||
default:
|
||||
case ConnectionState.active:
|
||||
case ConnectionState.done:
|
||||
if (snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user