반응형
1. 디펜던시 추가
pubspec.yaml
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
path_provider: #new
패키지 임포트
import 'package:path_provider/path_provider.dart';
2. FutureBuilder 보일러 플레이트
FutureBuilder<Directory>(
future: ~~~,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
} else {
return CircularProgressIndicator();
}
},
)
3. 폴더 경로 가져오기
getApplicationDocumentsDirectory()
getTemporaryDirectory()
getExternalStorageDirectory()
테스트해볼것.
getApplicationDocumentsDirectory() → Future<Directory>
getApplicationSupportDirectory() → Future<Directory>
getDownloadsDirectory() → Future<Directory?>
getExternalCacheDirectories() → Future<List<Directory>?>
getExternalStorageDirectories({StorageDirectory? type}) → Future<List<Directory>?>
getExternalStorageDirectory() → Future<Directory?>
getLibraryDirectory() → Future<Directory>
getTemporaryDirectory() → Future<Directory>
[전체소스]
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FutureBuilder<Directory>(
future: getTemporaryDirectory(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Text("tempDir : ${snapshot.data.path}");
} else {
return CircularProgressIndicator();
}
},
),
Divider(
height: 12.0,
),
FutureBuilder<Directory>(
future: getApplicationDocumentsDirectory(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Text("appDir : ${snapshot.data.path}");
} else {
return CircularProgressIndicator();
}
},
),
Divider(
height: 12.0,
),
FutureBuilder<Directory>(
future: getExternalStorageDirectory(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Text("externalDir : ${snapshot.data.path}");
} else {
return CircularProgressIndicator();
}
},
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
'flutter' 카테고리의 다른 글
데스트탑 플러터 (0) | 2020.11.11 |
---|---|
권한가져오기(checkPermissionStatus) (0) | 2019.11.13 |
Execution failed for task ':app:mergeDexDebug'. (3) | 2019.11.01 |
dart lang cheatsheet (0) | 2019.10.29 |
flutter cheatsheet (0) | 2019.10.29 |