Skip to content

Commit 113141b

Browse files
committed
fix: improve documentation and add example
1 parent cff403f commit 113141b

File tree

18 files changed

+355
-12
lines changed

18 files changed

+355
-12
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```dart
2+
import 'package:flutter/material.dart';
3+
import 'package:cross_cache/cross_cache.dart';
4+
5+
class MyWidget extends StatefulWidget {
6+
@override
7+
_MyWidgetState createState() => _MyWidgetState();
8+
}
9+
10+
class _MyWidgetState extends State<MyWidget> {
11+
final _cache = CrossCache(); // Create an instance
12+
13+
@override
14+
void dispose() {
15+
_cache.dispose(); // Dispose the cache
16+
super.dispose();
17+
}
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
return Image(
22+
image: CachedNetworkImage(
23+
'https://example.com/image.jpg',
24+
_cache, // Pass the cache instance
25+
headers: {'Authorization': 'Bearer YOUR_TOKEN'}, // Optional headers
26+
),
27+
loadingBuilder: (context, child, loadingProgress) {
28+
if (loadingProgress == null) return child;
29+
return Center(
30+
child: CircularProgressIndicator(
31+
value: loadingProgress.expectedTotalBytes != null
32+
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
33+
: null,
34+
),
35+
);
36+
},
37+
errorBuilder: (context, error, stackTrace) => Icon(Icons.error),
38+
);
39+
}
40+
}
41+
42+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
/// Cross Cache package. Provides a cache for images and files.
2+
library;
3+
14
export 'src/cached_network_image.dart';
25
export 'src/cross_cache.dart';
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
```dart
2+
import 'dart:math';
3+
4+
import 'package:flutter/material.dart';
5+
import 'package:flutter_chat_core/flutter_chat_core.dart';
6+
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
7+
8+
class Basic extends StatefulWidget {
9+
const Basic({super.key});
10+
11+
@override
12+
BasicState createState() => BasicState();
13+
}
14+
15+
class BasicState extends State<Basic> {
16+
final _chatController = InMemoryChatController();
17+
18+
@override
19+
void dispose() {
20+
_chatController.dispose();
21+
super.dispose();
22+
}
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
return Scaffold(
27+
body: Chat(
28+
chatController: _chatController,
29+
currentUserId: 'user1',
30+
onMessageSend: (text) {
31+
_chatController.insert(
32+
TextMessage(
33+
// Better to use UUID or similar for the ID - IDs must be unique
34+
id: '${Random().nextInt(1000) + 1}',
35+
authorId: 'user1',
36+
createdAt: DateTime.now().toUtc(),
37+
text: text,
38+
),
39+
);
40+
},
41+
resolveUser: (UserID id) async {
42+
return User(id: id, name: 'John Doe');
43+
},
44+
),
45+
);
46+
}
47+
}
48+
49+
```

packages/flutter_chat_core/lib/flutter_chat_core.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Flutter Chat Core package. Provides the core functionality for the flutter_chat_ui package.
2+
library;
3+
14
export 'src/chat_controller/chat_controller.dart';
25
export 'src/chat_controller/chat_operation.dart';
36
export 'src/chat_controller/in_memory_chat_controller.dart';
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
```dart
2+
import 'dart:math';
3+
4+
import 'package:flutter/material.dart';
5+
import 'package:flutter_chat_core/flutter_chat_core.dart';
6+
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
7+
8+
class Basic extends StatefulWidget {
9+
const Basic({super.key});
10+
11+
@override
12+
BasicState createState() => BasicState();
13+
}
14+
15+
class BasicState extends State<Basic> {
16+
final _chatController = InMemoryChatController();
17+
18+
@override
19+
void dispose() {
20+
_chatController.dispose();
21+
super.dispose();
22+
}
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
return Scaffold(
27+
body: Chat(
28+
chatController: _chatController,
29+
currentUserId: 'user1',
30+
onMessageSend: (text) {
31+
_chatController.insert(
32+
TextMessage(
33+
// Better to use UUID or similar for the ID - IDs must be unique
34+
id: '${Random().nextInt(1000) + 1}',
35+
authorId: 'user1',
36+
createdAt: DateTime.now().toUtc(),
37+
text: text,
38+
),
39+
);
40+
},
41+
resolveUser: (UserID id) async {
42+
return User(id: id, name: 'John Doe');
43+
},
44+
),
45+
);
46+
}
47+
}
48+
49+
```

packages/flutter_chat_ui/lib/flutter_chat_ui.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Flutter Chat UI package. Provides the UI for the Flyer Chat.
2+
library;
3+
14
export 'src/avatar.dart';
25
export 'src/chat.dart';
36
export 'src/chat_animated_list/chat_animated_list.dart';

packages/flutter_chat_ui/lib/src/chat_animated_list/chat_animated_list.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ class ChatAnimatedList extends StatefulWidget {
144144
});
145145

146146
@override
147-
ChatAnimatedListState createState() => ChatAnimatedListState();
147+
// ignore: library_private_types_in_public_api
148+
_ChatAnimatedListState createState() => _ChatAnimatedListState();
148149
}
149150

150151
/// State for [ChatAnimatedList].
151-
class ChatAnimatedListState extends State<ChatAnimatedList>
152+
class _ChatAnimatedListState extends State<ChatAnimatedList>
152153
with TickerProviderStateMixin, WidgetsBindingObserver, KeyboardMixin {
153154
final GlobalKey<SliverAnimatedListState> _listKey = GlobalKey();
154155
late final ChatController _chatController;

packages/flutter_chat_ui/lib/src/chat_animated_list/chat_animated_list_reversed.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ class ChatAnimatedListReversed extends StatefulWidget {
111111
});
112112

113113
@override
114-
ChatAnimatedListReversedState createState() =>
115-
ChatAnimatedListReversedState();
114+
// ignore: library_private_types_in_public_api
115+
_ChatAnimatedListReversedState createState() =>
116+
_ChatAnimatedListReversedState();
116117
}
117118

118119
/// State for [ChatAnimatedListReversed].
119-
class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
120+
class _ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
120121
with SingleTickerProviderStateMixin {
121122
final GlobalKey<SliverAnimatedListState> _listKey = GlobalKey();
122123
late final ChatController _chatController;

packages/flutter_chat_ui/lib/src/chat_message/chat_message_internal.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class ChatMessageInternal extends StatefulWidget {
4040
});
4141

4242
@override
43-
State<ChatMessageInternal> createState() => ChatMessageInternalState();
43+
State<ChatMessageInternal> createState() => _ChatMessageInternalState();
4444
}
4545

4646
/// State for [ChatMessageInternal].
47-
class ChatMessageInternalState extends State<ChatMessageInternal> {
47+
class _ChatMessageInternalState extends State<ChatMessageInternal> {
4848
late StreamSubscription<ChatOperation>? _operationsSubscription;
4949
late Message _updatedMessage;
5050

packages/flutter_chat_ui/lib/src/composer.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ class Composer extends StatefulWidget {
1313
/// Optional controller for the text input field.
1414
final TextEditingController? textEditingController;
1515

16-
/// Optional positioning properties.
16+
/// Optional left position.
1717
final double? left;
18+
19+
/// Optional right position.
1820
final double? right;
21+
22+
/// Optional top position.
1923
final double? top;
24+
25+
/// Optional bottom position.
2026
final double? bottom;
2127

22-
/// Optional blur values for the background (if using glassmorphism).
28+
/// Optional X blur value for the background (if using glassmorphism).
2329
final double? sigmaX;
30+
31+
/// Optional Y blur value for the background (if using glassmorphism).
2432
final double? sigmaY;
2533

2634
/// Padding around the composer content.

0 commit comments

Comments
 (0)