create media list view controller to handles media list view
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Controller for MediaListView Widget
|
||||||
|
class MediaListViewController extends ChangeNotifier {
|
||||||
|
var _shouldUpdateMedia = false;
|
||||||
|
|
||||||
|
/// Getter that knows if the media should be updated.
|
||||||
|
bool get shouldUpdateMedia => _shouldUpdateMedia;
|
||||||
|
|
||||||
|
/// Method that update shouldUpdateMedia and notify all listeners
|
||||||
|
/// about this update.
|
||||||
|
void updateMedia({required bool newValue}) {
|
||||||
|
_shouldUpdateMedia = newValue;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import 'package:stream_chat_flutter/src/media_list_view_controller.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('should update media', () {
|
||||||
|
final controller = MediaListViewController();
|
||||||
|
|
||||||
|
expect(controller.shouldUpdateMedia, false);
|
||||||
|
|
||||||
|
controller.updateMedia(newValue: true);
|
||||||
|
expect(controller.shouldUpdateMedia, true);
|
||||||
|
|
||||||
|
controller.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should notify listeners on update media', () {
|
||||||
|
final controller = MediaListViewController();
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
void updateCallsSpy() => callCount++;
|
||||||
|
|
||||||
|
controller.addListener(updateCallsSpy);
|
||||||
|
|
||||||
|
expect(callCount, 0);
|
||||||
|
controller.updateMedia(newValue: false);
|
||||||
|
expect(controller.shouldUpdateMedia, false);
|
||||||
|
expect(callCount, 1);
|
||||||
|
|
||||||
|
controller.updateMedia(newValue: true);
|
||||||
|
expect(controller.shouldUpdateMedia, true);
|
||||||
|
expect(callCount, 2);
|
||||||
|
|
||||||
|
controller
|
||||||
|
..removeListener(updateCallsSpy)
|
||||||
|
..dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user