|
- import 'package:chat/data/constants.dart';
- import 'package:chat/generated/i18n.dart';
- import 'package:chat/utils/screen.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
-
- import 'NetUtil.dart';
-
- class NetStateWidget extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
-
- return StreamBuilder(
- stream: NetWork().stream,
- initialData: ChatState.connecting,
- builder: (BuildContext context, AsyncSnapshot snapshot) {
- if (snapshot.data == ChatState.connecting.index) {
- return Container(
- color: Colors.white70,
- padding: EdgeInsets.symmetric(vertical: 5),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- CupertinoActivityIndicator(),
- SizedBox(width: 10),
- fixedText(I18n.of(context).connecting, color: Colors.grey[300])
- ]));
- } else if (snapshot.data == ChatState.logining.index) {
- return Container(
- color: Colors.white70,
- padding: EdgeInsets.symmetric(vertical: 5),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- CupertinoActivityIndicator(),
- SizedBox(width: 10),
- fixedText(I18n.of(context).logining, color: Colors.grey[300])
- ]));
- } else if (snapshot.data == ChatState.connectFailed.index ||
- snapshot.data == ChatState.loginFailed.index) {
- return InkWell(
- onTap: () {
- if (snapshot.data == ChatState.connectFailed.index) {
- NetWork().reconnect();
- } else {
- NetWork().reLogin();
- }
- },
- child: Container(
- color: Colors.white70,
- padding: EdgeInsets.symmetric(vertical: 5),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Icon(
- IconData(0xe649,
- fontFamily: Constants.IconFontFamily),
- color: Colors.grey),
- SizedBox(width: 10),
- fixedText(I18n.of(context).net_error,
- color: Colors.grey)
- ])));
- } else {
- return Container(
- height: 0,
- );
- }
- },
- );
- }
- }
|