kefu_flutter 1.0.1 copy "kefu_flutter: ^1.0.1" to clipboard
kefu_flutter: ^1.0.1 copied to clipboard

outdated

This is a customer service system based on Xiaomi Message Cloud. The flutter version may be the best open source customer service solution for flutter.

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:kefu_flutter/kefu_flutter.dart';

void main(){
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(statusBarColor: Color.fromRGBO(0, 0, 0, 0.0)));
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  return runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: '在线客服',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        brightness: Brightness.light,
        primaryColor: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter 在线客服 DEMO'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  KeFuStore _keFu;

  void _action() {
    Navigator.push(context, CupertinoPageRoute(builder: (ctx){
      return _keFu.view();
    }));
  }

  @override
  void initState() {

    // 配置文件 (1)
    KeFuStore.configs(
        debug: true,
        autoLogin: true,
        host: "http://kf.aissz.com:666/v1",
        appID: "2882303761518282099",
        appKey: "5521828290099",
        appSecret: "516JCA60FdP9bHQUdpXK+Q=="
    );

    // 获得实例并监听数据动态 (2)
    _keFu = KeFuStore.getInstance;

    // 获得实例并监听数据动态 (3)
    _keFu.addListener((){
      _keFu = KeFuStore.getInstance;
      debugPrint("_keFu对象变动");
      if(mounted) setState(() {});
    });

    super.initState();

  }


  @override
  void dispose() {
    _keFu?.dispose();
    super.dispose();
  }


  @override
  Widget build(BuildContext context) {
    ThemeData themeData = Theme.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RichText(
              text: TextSpan(
                style: TextStyle(
                  color: Colors.black
                ),
                children: [
                  TextSpan(text: "用户id: ${_keFu.imUser?.id ?? 0}   "),
                  TextSpan(text: "${_keFu.messageReadCount}", style: TextStyle(
                    color: Colors.deepOrange,
                    fontSize: 30.0,
                    fontWeight: FontWeight.w600
                  )),
                  TextSpan(text: "条未读消息"),
                ]
              ),
            ),
            Text(
              '欢迎使用在线客服',
            ),
            RaisedButton(
                color: themeData.primaryColor,
                child: Text("联系客服", style: TextStyle(color: Colors.white),), onPressed: () => _action()
            )
          ],
        ),
      ),
    );
  }
}
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

This is a customer service system based on Xiaomi Message Cloud. The flutter version may be the best open source customer service solution for flutter.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

cupertino_icons, dio, flutter, flutter_advanced_networkimage, flutter_mimc, image_picker, provider, shared_preferences

More

Packages that depend on kefu_flutter