Hibok
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

72 righe
2.7 KiB

  1. import 'package:chat/data/constants.dart';
  2. import 'package:chat/generated/i18n.dart';
  3. import 'package:chat/utils/screen.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'NetUtil.dart';
  7. class NetStateWidget extends StatelessWidget {
  8. @override
  9. Widget build(BuildContext context) {
  10. return StreamBuilder(
  11. stream: NetWork().stream,
  12. initialData: ChatState.connecting,
  13. builder: (BuildContext context, AsyncSnapshot snapshot) {
  14. if (snapshot.data == ChatState.connecting.index) {
  15. return Container(
  16. color: Colors.white70,
  17. padding: EdgeInsets.symmetric(vertical: 5),
  18. child: Row(
  19. mainAxisAlignment: MainAxisAlignment.center,
  20. children: <Widget>[
  21. CupertinoActivityIndicator(),
  22. SizedBox(width: 10),
  23. fixedText(I18n.of(context).connecting, color: Colors.grey[300])
  24. ]));
  25. } else if (snapshot.data == ChatState.logining.index) {
  26. return Container(
  27. color: Colors.white70,
  28. padding: EdgeInsets.symmetric(vertical: 5),
  29. child: Row(
  30. mainAxisAlignment: MainAxisAlignment.center,
  31. children: <Widget>[
  32. CupertinoActivityIndicator(),
  33. SizedBox(width: 10),
  34. fixedText(I18n.of(context).logining, color: Colors.grey[300])
  35. ]));
  36. } else if (snapshot.data == ChatState.connectFailed.index ||
  37. snapshot.data == ChatState.loginFailed.index) {
  38. return InkWell(
  39. onTap: () {
  40. if (snapshot.data == ChatState.connectFailed.index) {
  41. NetWork().reconnect();
  42. } else {
  43. NetWork().reLogin();
  44. }
  45. },
  46. child: Container(
  47. color: Colors.white70,
  48. padding: EdgeInsets.symmetric(vertical: 5),
  49. child: Row(
  50. mainAxisAlignment: MainAxisAlignment.center,
  51. children: <Widget>[
  52. Icon(
  53. IconData(0xe649,
  54. fontFamily: Constants.IconFontFamily),
  55. color: Colors.grey),
  56. SizedBox(width: 10),
  57. fixedText(I18n.of(context).net_error,
  58. color: Colors.grey)
  59. ])));
  60. } else {
  61. return Container(
  62. height: 0,
  63. );
  64. }
  65. },
  66. );
  67. }
  68. }