상식닷컴
로그인
가입하기
2026년 상식닷컴 선정 식당 & 카페 리스트
2025년 2026년 신상 호텔 리스트
최근에 오픈한 호텔을 찾는다면 살펴보세요
일주일 식단표 어플
자동 일주일 식단표 어플
안드로이드
아이폰
주식 & 코인 차트의 신
1000만원으로 2000만원 만들기 프로젝트
수정하기 - Flutter에서 CircularProgressIndicator를 사용하는 방법은 무엇인가요?
닉네임
비밀번호
제목
내용
[이미지 업로드는 권한이 있는 사람만 가능. 하단 카톡으로 연락]
Flutter에서 `CircularProgressIndicator`는 비동기 작업이 진행 중임을 사용자에게 알리기 위해 사용되는 위젯입니다. 이 위젯은 일반적으로 데이터 로딩, 파일 다운로드, 또는 기타 시간이 걸리는 작업을 수행할 때 사용됩니다. `CircularProgressIndicator`는 원형 모양의 로딩 인디케이터로, 사용자가 작업이 진행 중임을 시각적으로 인식할 수 있도록 도와줍니다. 기본 사용법 `CircularProgressIndicator`를 사용하기 위해서는 Flutter의 기본 위젯 트리 내에 추가하면 됩니다. 아래는 기본적인 사용 예제입니다. ```dart import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext <a href='https://sangseek.com/sangseeks/context/ko'>context</a>) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('CircularProgressIndicator 예제'), ), body: Center( child: CircularProgressIndicator(), ), ), ); } } ``` 위의 코드에서는 `CircularProgressIndicator`를 화면 중앙에 배치하여 로딩 상태를 표시합니다. 색상 및 <a href='https://sangseek.com/sangseeks/크기 조정/ko'>크기 조정</a> `CircularProgressIndicator`는 `valueColor`와 `strokeWidth` 속성을 사용하여 색상과 두께를 조정할 수 있습니다. - `valueColor`: 로딩 인디케이터의 색상을 설정합니다. `AlwaysStoppedAnimation<Color>`를 사용하여 색상을 지정할 수 있습니다. - `strokeWidth`: 인디케이터의 두께를 설정합니다. 아래는 색상과 두께를 조정한 예제입니다. ```dart CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>(Colors.blue), strokeWidth: 6.0, ) ``` 비동기 작업과 함께 사용하기 `CircularProgressIndicator`는 일반적으로 비동기 작업과 함께 사용됩니다. 예를 들어, 데이터를 로드하는 동안 로딩 인디케이터를 표시할 수 있습니다. 아래는 비동기 작업을 수행하는 예제입니다. ```dart import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends <a href='https://sangseek.com/sangseeks/StatefulWidget/ko'>StatefulWidget</a> { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { bool _isLoading = false; Future<void> _loadData() async { setState(() { _isLoading = true; }); // Simulate a network request await Future.delayed(Duration(seconds: 3)); setState(() { _isLoading = false; }); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('CircularProgressIndicator 예제'), ), body: Center( child: _isLoading ? CircularProgressIndicator() : ElevatedButton( onPressed: _loadData, child: Text('데이터 로드'), ), ), ), ); } } ``` 위의 예제에서는 버튼을 클릭하면 `_loadData` 함수가 호출되고, 이 함수 내에서 3초 동안 로딩 상태를 표시합니다. 로딩이 완료되면 버튼이 다시 나타납니다. 결론 `CircularProgressIndicator`는 Flutter에서 비동기 작업의 <a href='https://sangseek.com/sangseeks/진행 상태/ko'>진행 상태</a>를 사용자에게 알리는 데 유용한 위젯입니다. 색상과 두께를 조정할 수 있으며, 비동기 작업과 함께 사용하여 사용자 경험을 향상시킬 수 있습니다. 이 위젯을 적절히 활용하면 앱의 로딩 상태를 효과적으로 관리할 수 있습니다.
이용안내
커뮤니티 이용안내
×
- 게시한 게시글로 발생하는 문제는 게시자에게 책임이 있습니다.
- 게시글이 타인/타업체의 저작권을 침해할 경우 모든 책임은 게시자에게 있습니다. 게시자가 모든 손해를 부담해야 합니다.
- 상식닷컴 운영자는 게시자와 상의하지 않고 게시글을 수정 또는 삭제할 수 있습니다.
- 상식닷컴 운영자는 깨끗한 커뮤니티 공간을 만드는 것이 1순위입니다.
수정하기
취소하기