-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToast.dart
74 lines (67 loc) · 1.71 KB
/
Toast.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import './CreateLayer.dart';
import 'dart:async';
import './setTimeout.dart';
const _backgroundColor = Color.fromRGBO(0, 0, 0, 0.9);
const _activeColor = Color.fromRGBO(255,255,255, 1);
class Toast {
static CreateLayer _cty = new CreateLayer(true);
static Timer _timer;
static build (BuildContext context, Widget child) {
_cty?.close();
_cty.show(
context: context,
builder: (ctx, constraints) {
return child;
}
);
}
static _base ({
@required BuildContext context,
@required String message,
Color color = _activeColor,
int duration
}) {
if(duration == null) {
duration = 2000;
}
_cty.close();
_timer?.cancel();
_timer = setTimeout(_cty.close, duration);
_cty.show(
context: context,
builder: (ctx, constraints) {
return Center(
child: Container(
decoration: new BoxDecoration(
color: _backgroundColor,
borderRadius: BorderRadius.circular(5)
),
padding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
child: Text(message, style: new TextStyle(
color: color,
fontSize: 14.0,
decoration: TextDecoration.none,
)),
),
);
}
);
}
static info (BuildContext context, String message, [int duration]) {
_base(
context: context,
message: message,
duration: duration
);
}
static danger (BuildContext context, String message, [int duration]) {
_base(
context: context,
message: message,
color: Colors.red,
duration: duration
);
}
}