chatbook 0.0.2
chatbook: ^0.0.2 copied to clipboard
A complete chat ui
example/lib/main.dart
import 'package:chatbook/chatbook.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import "package:google_fonts/google_fonts.dart" show GoogleFonts;
import 'package:isolated_worker/worker_delegator.dart';
int foo(int count) {
int result = 0;
for (int i = 1; i <= count; i++) {
result += i;
print(result);
}
return result;
}
Future<void> main() async {
DefaultDelegate<int, int> fooDelegate = const DefaultDelegate(callback: foo);
const JsDelegate fooJsDelegate = JsDelegate(callback: 'foo');
WorkerDelegate<int, int> workerDelegate = WorkerDelegate(
key: 'foo',
defaultDelegate: fooDelegate,
jsDelegate: fooJsDelegate,
);
WorkerDelegator().addDelegate(workerDelegate);
// Don't forget to call importScripts for our "foo" js method.
await WorkerDelegator().importScripts(const <String>['foojs.js']);
runApp(const ChatBookApp());
}
class ChatBookApp extends StatelessWidget {
const ChatBookApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(textTheme: GoogleFonts.poppinsTextTheme()),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
ValueNotifier<List<Message>> _notifierMssagesList = ValueNotifier([
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text:
'''Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
]);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
automaticallyImplyLeading: false,
backgroundColor: const Color(0Xff010101),
flexibleSpace: SafeArea(
child: Container(
padding: const EdgeInsets.only(right: 16),
child: Row(
children: <Widget>[
IconButton(
onPressed: () async {
int result = await WorkerDelegator().run('foo', 100000);
},
icon: const Icon(
CupertinoIcons.chevron_back,
color: Colors.white,
),
),
const SizedBox(
width: 2,
),
const CircleAvatar(
// backgroundImage: NetworkImage(
// "https://randomuser.me/api/portraits/men/5.jpg"
// ),
maxRadius: 20,
),
const SizedBox(
width: 12,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
"Kriss Benawat",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.white),
),
SizedBox(
height: 6,
),
Text(
"Online",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Colors.white),
),
],
),
),
IconButton(
icon: const Icon(
CupertinoIcons.phone,
color: Color.fromRGBO(255, 255, 255, .87),
),
onPressed: () {
List<Message> newList =
List<Message>.from(_notifierMssagesList.value);
newList.insert(
0,
TextMessage(
author: const User(id: '11111'),
text: 'Hi',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
));
_notifierMssagesList.value = newList;
},
),
const SizedBox(
width: 20,
),
IconButton(
icon: const Icon(
CupertinoIcons.video_camera,
color: Color.fromRGBO(255, 255, 255, .87),
),
onPressed: () {},
),
],
),
),
),
),
backgroundColor: const Color(0XFF010101),
body: ValueListenableBuilder(
valueListenable: _notifierMssagesList,
builder: (context, value, child) {
value as List<Message>;
return ChatBook(
author: const User(id: "1", firstName: "Yogesh"),
giphyApiKey: 'HbrIuc2uiEvkJKgCIrZw3n68ukoiycsUu',
prevMessages: value,
onSendMessage: (Message message) {
// print(message.self);
},
onLoadEarlierMessages: (loadEarlierMessages) {
loadEarlierMessages.call([
TextMessage(
author: const User(id: '11111'),
text: '''Hii''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
TextMessage(
author: const User(id: '11111'),
text: '''Hii''',
id: uuid.v4(),
createdAt: DateTime.now().millisecondsSinceEpoch,
),
]);
},
);
},
),
);
}
}