state_persistence
앱 시작 간에 상태를 유지합니다. 기본적으로 이 라이브러리는 앱의 데이터 디렉터리에 있는 로컬 JSON 파일인 `data.json`로 상태를 저장합니다.
상태 유지 - 앱 재시작 간 상태를 유지합니다. 기본적으로 이 라이브러리는 애플리케이션 데이터 디렉터리에 로컬 JSON 파일인 `data.json`로 상태를 저장합니다. 유지보수자: @slightfoot
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Persist state across app launches. By default this library store
state as a local JSON file called data.json in the applications
data directory. You can change this filename by providing another
storage mechanism.
If you do not want to store your persisted app state as a JSON
file you can extend PersistedStateStorage and provide your own
methods for saving and loading data. E.g shared_preferences or
sqflite. For those of you that are ambitious you could even
store your state on the web or even in Firebase.
To change the persisted state simply modify the values in the
data map. These changes will automatically be persisted to disk
based on the saveTimeout given to the PersistedAppState widget.
By default this value is 500 milliseconds. This timeout is used
to stop disk thrashing on multiple map changes in quick succession.
import 'package:flutter/material.dart';
import 'package:state_persistence/state_persistence.dart';
void main() => runApp(App());
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
TextEditingController _textController;
@override
Widget build(BuildContext context) {
return PersistedAppState(
storage: JsonFileStorage(),
child: MaterialApp(
title: 'Persistent TextField Example',
theme: ThemeData(primarySwatch: Colors.indigo),
home: Scaffold(
appBar: AppBar(title: Text('Persistent TextField Example')),
body: Container(
padding: const EdgeInsets.all(32.0),
alignment: Alignment.center,
child: PersistedStateBuilder(
builder: (BuildContext context, AsyncSnapshot<PersistedData> snapshot) {
if (snapshot.hasData) {
if (_textController == null) {
_textController = TextEditingController(text: snapshot.data['text'] ?? '');
}
return TextField(
controller: _textController,
decoration: InputDecoration(
hintText: 'Enter some text',
),
onChanged: (String value) => snapshot.data['text'] = value,
);
} else {
return CircularProgressIndicator();
}
},
),
),
),
),
);
}
}
의존성 목록 4 개
^1.8.0^2.0.1{"sdk":"flutter"}{"sdk":"flutter"}사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗