패키지, 저장소 및 앱 카테고리 검색

oktoast 표지
패키지 상세v3.4.0

oktoast

순수한 플러터 토스트 라이브러리로, 사용자 정의 스타일/위젯을 지원하며 네이티브 토스트와 동일한 효과를 쉽게 구현할 수 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
4.5만
좋아요
361
Pub 점수
160

패키지 설치

flutter pub add oktoast

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

oktoast는 모든 플랫폼에서 네이티브처럼 보이는 토스트 알림을 제공하도록 설계된 가벼운 순수 Flutter 토스트 라이브러리입니다. 사용자 정의 스타일과 위젯을 지원하여 개발자가 시각적으로 일관되고 매우 커스터마이징 가능한 토스트 메시지를 만들 수 있습니다. 단일 명령어를 통해 간단히 통합할 수 있어 앱 내에서 부드럽고 방해되지 않는 피드백을 신속하게 구현할 수 있습니다. 이 라이브러리는 지속적으로 유지보수되며 Android, iOS, Web, macOS, Windows 및 Linux와 호환됩니다.

사용 사례

  • 사용자 간단 피드백 표시
  • 성공 또는 오류 메시지 표시
  • 토스트 외관 맞춤 설정
  • 임시 상태 업데이트 제공
  • UI 반응성 향상
  • 기본 플러터 스낵바 교체

주요 기능

  • 사용자 정의 위젯 및 스타일을 지원합니다
  • 크로스 플랫폼 호환성
  • 빠른 설정을 위한 간단한 API
  • 비차단식 토스트 표시
  • 사용자 정의 가능한 지속 시간 및 위치
  • 경량이며 성능이 뛰어남

적합한 대상

  • 모바일 앱 피드백
  • 웹 애플리케이션 알림
  • 데스크톱 앱 사용자 힌트
  • 일관된 토스트 디자인을 필요로 하는 앱
  • 최소한의 종속성 원하는 개발자
  • 플랫폼에 관계없이 사용 가능한 토스트가 필요한 프로젝트

고려 사항

  • 복잡한 레이아웃을 위해 추가 스타일링이 필요할 수 있습니다
  • 제한된 내장 애니메이션
  • 지속적인 알림에 적합하지 않음
  • 여러 Toast를 수동으로 관리해야 합니다
  • 일시적인 메시지에만 적합
  • 내장된 로컬라이제이션 지원 없음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

oktoast

oktoast pub package GitHub GitHub stars

A library for flutter.

A pure dart toast Library.

You can completely customize the style of toast.

中文博客介绍

Screenshot

Default Custom GIF
pic pic pic

Versions

3.x.x

Starting from the 3.x version, OKToast provides a null-safety version, the specific introduction of null-safety can be viewed in dart or flutter.

The 2.3.2 version is the last version that does not support null-safety.

About version 1.x

if you use OKToast 1.x, Please use the 1.x branch, and read version readme.

Proposed migration to 2.x version. The new version does not require buildContext.

And you can completely customize the style of toast, because now you can use showToastWidget.

Usage

1. Add library to your pubspec.yaml
flutter pub add oktoast
2. Import library in dart file
import 'package:oktoast/oktoast.dart';
3. Wrap your app widget
OKToast(
  /// set toast style, optional
  child:MaterialApp()
);

Tips: If you happened error like: No MediaQuery widget found, you can try to use this code to include OKToast to your App.

MaterialApp(
  builder: (BuildContext context, Widget? widget) {
    return OKToast(child: widget);
  },
);
4. Call method showToast
showToast('content');

// position and second have default value, is optional
showToastWidget(Text('hello oktoast'));

Explain

There are two reasons why you need to wrap MaterialApp

  1. Because this ensures that toast can be displayed in front of all other controls
  2. Context can be cached so that it can be invoked anywhere without passing in context

Properties

OKToast params

OKToast have default style, and you also can custom style or other behavior.

name type need desc
child Widget required Usually Material App
textStyle TextStyle optional
radius double optional
backgroundColor Color optional backroundColor
position ToastPosition optional
dismissOtherOnShow bool optional If true, other toasts will be dismissed. Default false.
movingOnWindowChange bool optional If true, when the size changes, toast is moved. Default true.
textDirection TextDirection optional
textPadding EdgeInsetsGeometry optional Outer margin of text
textAlign TextAlign optional When the text wraps, the align of the text.
handleTouch bool optional Default is false, if it's true, can responed use touch event.
animationBuilder OKToastAnimationBuilder optional Add animation to show / hide toast.
animationDuration Duration optional The duration of animation.
animationCurve Curve optional Curve of animation.
duration Duration optional Default duration of toast.
Method showToast

Display text on toast.

Description of params see OKToast.

name type need desc
msg String required Text of toast.
context BuildContext optional
duration Duration optional
position ToastPosition optional
textStyle TextStyle optional
textPadding EdgeInsetsGeometry optional
backgroundColor Color optional
radius double optional
onDismiss Function optional
textDirection TextDirection optional
dismissOtherToast bool optional
textAlign TextAlign optional
animationBuilder OKToastAnimationBuilder optional
animationDuration Duration optional
animationCurve Curve optional
Method showToastWidget

Display custom widgets on toast

Description of params see showToast.

name type need desc
widget Widget required The widget you want to display.
context BuildContext optional
duration Duration optional
position ToastPosition optional
onDismiss Function optional
dismissOtherToast bool optional
textDirection TextDirection optional
handleTouch bool optional
animationBuilder OKToastAnimationBuilder optional
animationDuration Duration optional
animationCurve Curve optional
Method dismissAllToast

Dismiss all toast.

Return value of showToast and showToastWidget

about return type:
showToast and showToastWidget return type is ToastFuture, The ToastFuture can be use to dismiss the toast.

For all dismiss toast method

An optional parameter showAnim is added to control whether fading animation is required for dismiss.

The praram default value is false.

Examples

import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart'; // 1. import library

void main() => runApp( MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OKToast(
      // 2. wrap your app with OKToast
      child:  MaterialApp(
        title: 'Flutter Demo',
        theme:  ThemeData(
          primarySwatch: Colors.blue,
        ),
        home:  MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() =>  _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    _counter++;

    // 3.1 use showToast method
    showToast(
      "$_counter",
      duration: Duration(seconds: 2),
      position: ToastPosition.bottom,
      backgroundColor: Colors.black.withOpacity(0.8),
      radius: 13.0,
      textStyle: TextStyle(fontSize: 18.0),
    );

    showToast(
      "$_counter",
      duration: Duration(seconds: 2),
      position: ToastPosition.top,
      backgroundColor: Colors.black.withOpacity(0.8),
      radius: 3.0,
      textStyle: TextStyle(fontSize: 30.0),
    );

    // 3.2 use showToastWidget method to custom widget
    Widget widget = Center(
      child: ClipRRect(
        borderRadius: BorderRadius.circular(30.0),
        child: Container(
          width: 40.0,
          height: 40.0,
           color: Colors.grey.withOpacity(0.3),
          child: Icon(
            Icons.add,
            size: 30.0,
            color: Colors.green,
          ),
        ),
      ),
    );

    ToastFuture toastFuture = showToastWidget(
      widget,
      duration: Duration(seconds: 3),
      onDismiss: () {
        print("the toast dismiss"); // the method will be called on toast dismiss.
      },
    );

    // can use future
    Future.delayed(Duration(seconds: 1), () {
      toastFuture.dismiss(); // dismiss
    });

    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar:  AppBar(
        title:  Text("ktoast demo"),
      ),
      body: Stack(
        children: <Widget>[
           Center(
            child: ListView(
              children: <Widget>[
                 Text(
                  'You have pushed the button this many times:',
                ),
                 Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.display1,
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    onPressed: () {
                      Navigator.push(context,
                          MaterialPageRoute(builder: (ctx) => MyHomePage()));
                    },
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    onPressed: _incrementCounter,
                    child: Text('toast'),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}


CHANGELOG

Link

LICENSE

Apache-2.0

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트