flutter_openchat 0.0.5 copy "flutter_openchat: ^0.0.5" to clipboard
flutter_openchat: ^0.0.5 copied to clipboard

Flutter package that help integrate your app with open source chat https://openchat.so

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_openchat/flutter_openchat.dart';

ThemeType _themeType = ThemeType();
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ListenableBuilder(
      listenable: _themeType,
      builder: (context, child) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(
              seedColor: Colors.blue,
              brightness: _themeType.brightness,
            ),
            useMaterial3: true,
          ),
          home: const MyHomePage(),
        );
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('OpenChat example'),
        actions: [
          IconButton(
            onPressed: () {
              if (_themeType.brightness == Brightness.dark) {
                _themeType.setLight();
              } else {
                _themeType.setDark();
              }
            },
            icon: Icon(
              _themeType.isLight ? Icons.nightlight : Icons.sunny,
            ),
          )
        ],
      ),
      body: FlutterOpenChatWidget(
        llm: OpenChatTeamLLM(),
        assetBotAvatar:
            'https://api.dicebear.com/7.x/bottts-neutral/png?seed=Harley&radius=50',
        assetUserAvatar:
            'https://api.dicebear.com/7.x/avataaars-neutral/png?seed=Jack&radius=50',
        backgroundEmpty: const Center(
          child: Text('Hothing over here'),
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class ThemeType extends ChangeNotifier {
  Brightness brightness = Brightness.light;

  bool get isLight => brightness == Brightness.light;

  void setLight() {
    brightness = Brightness.light;
    notifyListeners();
  }

  void setDark() {
    brightness = Brightness.dark;
    notifyListeners();
  }
}
10
likes
130
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter package that help integrate your app with open source chat https://openchat.so

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, markdown_widget

More

Packages that depend on flutter_openchat