flutter_bot 0.0.7 copy "flutter_bot: ^0.0.7" to clipboard
flutter_bot: ^0.0.7 copied to clipboard

A Flutter chatbot widget

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_bot/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: 'dfc3c805-6243-4c51-aa81-e52edc519ff6',
                userID: "2",
                currentLocale: currentLanguage,
              ),
            ),
          ),
        ],
      ),
    );
  }
}