본문 바로가기
Flutter

조금 더 화려한 Snackbar - Flushbar

by YoonTaeseong 2019. 10. 5.

지금까지 내가 스낵바를 띄우기 위해 사용했던 방법은 다음과 같다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Future<void> signUp(
      String email, String password, BuildContext context) async {
    try {
      final response = await http.post(
        Router.signUpUrl,
        body: json.encode(
          {
            'email': email,
            'password': password,
            'returnSecureToken'true,
          },
        ),
      );
      print(jsonDecode(response.body));
      if (response.statusCode >= 400) {
          content: Text('이미 존재하는 아이디 입니다.'),
          duration: Duration(milliseconds: 2),
        ));
      }
    } catch (error) {
      print(error.toString());
    }
 }
 

 

하지만 사용하다 보니 이런 에러가 작성되었다.

 

아마도 내가 느끼기로는 Scaffold.of 함수는 가장 가까이 있는 Scaffold를 호출하는 함수라고 알고 있다 즉 현재 해당 클래스에 있는 Scaffold를 참조하는 거 같았다.

 

provider 에서 RESTAPI errorStateCode 400 이상일 때 스낵바를 하나 띄우고 싶었는데 provider 안에서는 Scaffold를 참조할 수 있는 방법이 없을까 하다가 다른 다트 패키지 중에 Flushbar라는 조금 더 이쁜 스낵바를 찾게 되었다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
if (response.statusCode >= 400) {
        Flushbar(
          duration: Duration(seconds: 2),
          icon: Icon(
            Icons.info,
            color: Theme.of(context).primaryTextTheme.title.color,
          ),
          title: '존재하는 아이디 입니다.',
          message: '다른 아이디를 이용해주세요',
          leftBarIndicatorColor: Theme.of(context).errorColor,
        ).show(context);
      }
 

 

바로 Flushbar라는 위젯이다.

 

 

flushbar | Flutter Package

A flexible widget for user notification. Customize your text, button, duration, animations and much more. For Android devs, it is made to replace Snackbars and Toasts.

pub.dev

 

해당 위젯을 쓰기위해선 title 파라 매터, message파라 매터는 반드시 존재해야 하는 듯했다. 마지막엔 반드시. show()를 해주어야 한다.

show 매개변수는 BuildContext를 받는다.

 
 

 

'Flutter' 카테고리의 다른 글

GridView정의 두가지 방법  (0) 2019.10.18
FutureBuilder정의  (0) 2019.10.15
fancy_bottom_navigation사용기  (0) 2019.10.13
플러터 dependencies 다운  (0) 2019.10.08
ios GoogleDataTransport 오류  (0) 2019.10.06

댓글