widget_chat 0.0.9 copy "widget_chat: ^0.0.9" to clipboard
widget_chat: ^0.0.9 copied to clipboard

A Flutter chatbot widget

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:widget_chat/chat_widget.dart';

void main() {
  runApp(const MyECommerceApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Sample App',
      home: const HomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String currentLanguage = 'en';

  void toggleLanguage() {
    setState(() {
      currentLanguage = currentLanguage == 'en' ? 'fr' : 'en';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          currentLanguage == 'en' ? 'Sample App' : 'Application Exemple',
        ),
        actions: [
          TextButton(
            onPressed: toggleLanguage,
            child: Text(
              currentLanguage == 'en' ? '🇫🇷 Français' : '🇬🇧 English',
            ),
          ),
        ],
      ),
      body: Stack(
        children: [
          Center(
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 24.0),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    currentLanguage == 'en'
                        ? 'Welcome to our store!'
                        : 'Bienvenue dans notre magasin!',
                    style: const TextStyle(
                      fontSize: 28,
                      fontWeight: FontWeight.bold,
                    ),
                    textAlign: TextAlign.center,
                  ),
                  const SizedBox(height: 24),
                  Text(
                    currentLanguage == 'en'
                        ? 'Chat with our support bot in the bottom right'
                        : 'Discutez avec notre bot d\'assistance en bas à droite',
                    style: const TextStyle(fontSize: 16, color: Colors.grey),
                    textAlign: TextAlign.center,
                  ),
                ],
              ),
            ),
          ),
          Align(
            alignment: Alignment.bottomRight,
            child: ChatWidget(
              configuration: BotConfiguration(
                projectSecretKey: '7b035777-f3f6-4ab1-acd9-5d46a1d2ccca',
                userID: "1",
                currentLocale: currentLanguage,
              ),
            ),
          ),
        ],
      ),
    );
  }
}