chore: move controllers from ui to core

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2022-02-07 15:25:07 +05:30
committed by xsahil03x
parent ce22e854a8
commit 202af02f8e
12 changed files with 44 additions and 71 deletions
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
/// A [SafeArea] with an enabled toggle
class SimpleSafeArea extends StatefulWidget {
class SimpleSafeArea extends StatelessWidget {
/// Constructor for [SimpleSafeArea]
const SimpleSafeArea({
Key? key,
@@ -15,17 +15,12 @@ class SimpleSafeArea extends StatefulWidget {
/// Child widget to wrap
final Widget child;
@override
_SimpleSafeAreaState createState() => _SimpleSafeAreaState();
}
class _SimpleSafeAreaState extends State<SimpleSafeArea> {
@override
Widget build(BuildContext context) => SafeArea(
left: widget.enabled,
top: widget.enabled,
right: widget.enabled,
bottom: widget.enabled,
child: widget.child,
left: enabled,
top: enabled,
right: enabled,
bottom: enabled,
child: child,
);
}
@@ -1,11 +1,8 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter/src/extension.dart';
import 'package:stream_chat_flutter/src/paged_value_notifier.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
import 'package:stream_chat_flutter/src/stream_svg_icon.dart';
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_controller.dart';
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_loading_tile.dart';
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_tile.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
@@ -25,8 +25,6 @@ export 'src/mention_tile.dart';
export 'src/message_action.dart';
export 'src/message_input/countdown_button.dart';
export 'src/message_input/message_input.dart';
export 'src/message_input/message_input_controller.dart';
export 'src/message_input/message_text_field_controller.dart';
export 'src/message_input/stream_attachment_picker.dart';
export 'src/message_input/stream_message_send_button.dart';
export 'src/message_input/stream_message_text_field.dart';
@@ -55,8 +53,6 @@ export 'src/user_mention_tile.dart';
export 'src/utils.dart';
// v4
export 'src/v4/channel_list_view/stream_channel_list_controller.dart';
export 'src/v4/channel_list_view/stream_channel_list_event_handler.dart';
export 'src/v4/channel_list_view/stream_channel_list_loading_tile.dart';
export 'src/v4/channel_list_view/stream_channel_list_tile.dart';
export 'src/v4/channel_list_view/stream_channel_list_view.dart';
@@ -1,14 +0,0 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void main() {
testWidgets(
'should instantiate a new MessageInputController with empty message',
(tester) async {
final controller = MessageInputController()..text = 'test';
expect(controller.text, 'test');
expect(controller.message.text, 'test');
},
);
}
@@ -2,7 +2,9 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter_core/src/message_text_field_controller.dart';
/// A value listenable builder related to a [Message].
///
@@ -1,6 +1,4 @@
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/message_input/tld.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// A function that takes a [BuildContext] and returns a [TextStyle].
typedef TextStyleBuilder = TextStyle? Function(
@@ -33,17 +31,8 @@ class MessageTextFieldController extends TextEditingController {
TextStyle? style,
required bool withComposing,
}) {
final pattern = textPatternStyle ??
{
RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+'):
(context, text) {
if (!text.split('.').last.isValidTLD()) return null;
return TextStyle(
color: MessageInputTheme.of(context).linkHighlightColor,
);
},
};
if (pattern.isEmpty) {
final pattern = textPatternStyle;
if (pattern == null || pattern.isEmpty) {
return super.buildTextSpan(
context: context,
style: style,
@@ -191,22 +191,20 @@ class _$Success<Key, Value> extends Success<Key, Value>
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is Success<Key, Value> &&
(identical(other.items, items) ||
const DeepCollectionEquality().equals(other.items, items)) &&
(identical(other.nextPageKey, nextPageKey) ||
const DeepCollectionEquality()
.equals(other.nextPageKey, nextPageKey)) &&
(identical(other.error, error) ||
const DeepCollectionEquality().equals(other.error, error)));
(other.runtimeType == runtimeType &&
other is Success<Key, Value> &&
const DeepCollectionEquality().equals(other.items, items) &&
const DeepCollectionEquality()
.equals(other.nextPageKey, nextPageKey) &&
const DeepCollectionEquality().equals(other.error, error));
}
@override
int get hashCode =>
runtimeType.hashCode ^
const DeepCollectionEquality().hash(items) ^
const DeepCollectionEquality().hash(nextPageKey) ^
const DeepCollectionEquality().hash(error);
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(items),
const DeepCollectionEquality().hash(nextPageKey),
const DeepCollectionEquality().hash(error));
@JsonKey(ignore: true)
@override
@@ -296,13 +294,13 @@ abstract class Success<Key, Value> extends PagedValue<Key, Value> {
const Success._() : super._();
/// List with all items loaded so far.
List<Value> get items => throw _privateConstructorUsedError;
List<Value> get items;
/// The key for the next page to be fetched.
Key? get nextPageKey => throw _privateConstructorUsedError;
Key? get nextPageKey;
/// The current error, if any.
StreamChatError? get error => throw _privateConstructorUsedError;
StreamChatError? get error;
@JsonKey(ignore: true)
$SuccessCopyWith<Key, Value, Success<Key, Value>> get copyWith =>
throw _privateConstructorUsedError;
@@ -347,7 +345,8 @@ class _$Loading<Key, Value> extends Loading<Key, Value>
@override
bool operator ==(dynamic other) {
return identical(this, other) || (other is Loading<Key, Value>);
return identical(this, other) ||
(other.runtimeType == runtimeType && other is Loading<Key, Value>);
}
@override
@@ -490,14 +489,14 @@ class _$Error<Key, Value> extends Error<Key, Value>
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is Error<Key, Value> &&
(identical(other.error, error) ||
const DeepCollectionEquality().equals(other.error, error)));
(other.runtimeType == runtimeType &&
other is Error<Key, Value> &&
const DeepCollectionEquality().equals(other.error, error));
}
@override
int get hashCode =>
runtimeType.hashCode ^ const DeepCollectionEquality().hash(error);
Object.hash(runtimeType, const DeepCollectionEquality().hash(error));
@JsonKey(ignore: true)
@override
@@ -583,7 +582,7 @@ abstract class Error<Key, Value> extends PagedValue<Key, Value> {
const factory Error(StreamChatError error) = _$Error<Key, Value>;
const Error._() : super._();
StreamChatError get error => throw _privateConstructorUsedError;
StreamChatError get error;
@JsonKey(ignore: true)
$ErrorCopyWith<Key, Value, Error<Key, Value>> get copyWith =>
throw _privateConstructorUsedError;
@@ -2,8 +2,9 @@ import 'dart:async';
import 'dart:math';
import 'package:stream_chat/stream_chat.dart' hide Success;
import 'package:stream_chat_flutter/src/paged_value_notifier.dart';
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_event_handler.dart';
import 'package:stream_chat_flutter_core/src/paged_value_notifier.dart';
import 'package:stream_chat_flutter_core/src/stream_channel_list_event_handler.dart';
/// The default channel page limit to load.
const defaultChannelPagedLimit = 10;
@@ -1,5 +1,5 @@
import 'package:stream_chat/stream_chat.dart' show ChannelState, Event;
import 'package:stream_chat_flutter/src/v4/channel_list_view/stream_channel_list_controller.dart';
import 'package:stream_chat_flutter_core/src/stream_channel_list_controller.dart';
/// Contains handlers that are called from [StreamChannelListController] for
/// certain [Event]s.
@@ -7,10 +7,15 @@ export 'src/better_stream_builder.dart';
export 'src/channel_list_core.dart' hide ChannelListCoreState;
export 'src/channels_bloc.dart';
export 'src/lazy_load_scroll_view.dart';
export 'src/message_input_controller.dart';
export 'src/message_list_core.dart' hide MessageListCoreState;
export 'src/message_search_bloc.dart';
export 'src/message_search_list_core.dart' hide MessageSearchListCoreState;
export 'src/message_text_field_controller.dart';
export 'src/paged_value_notifier.dart' show PagedValueListenableBuilder;
export 'src/stream_channel.dart';
export 'src/stream_channel_list_controller.dart';
export 'src/stream_channel_list_event_handler.dart';
export 'src/stream_chat_core.dart';
export 'src/typedef.dart';
export 'src/user_list_core.dart' hide UserListCoreState;
@@ -14,14 +14,17 @@ dependencies:
connectivity_plus: ^2.1.0
flutter:
sdk: flutter
freezed_annotation: ^1.0.0
meta: ^1.3.0
rxdart: ^0.27.0
stream_chat: ^3.3.1
dev_dependencies:
build_runner: ^2.0.1
dart_code_metrics: ^4.4.0
fake_async: ^1.2.0
flutter_test:
sdk: flutter
freezed: ^1.0.0
mocktail: ^0.2.0