using System; using System.Collections.Generic; using System.Linq; using ChatComponents; using uiwidgets; using Unity.UIWidgets.animation; using Unity.UIWidgets.foundation; using Unity.UIWidgets.material; using Unity.UIWidgets.painting; using Unity.UIWidgets.rendering; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; using Image = Unity.UIWidgets.widgets.Image; namespace UIWidgetsSample { public abstract class Conditional { /// Creates a new platform appropriate conditional. /// /// Creates an `IOConditional` if `dart:io` is available and a `BrowserConditional` if /// `dart:html` is available, otherwise it will throw an unsupported error. public Conditional() => createConditional(); /// Returns an appropriate platform ImageProvider for specified URI public abstract ImageProvider getProvider(string uri); public abstract BaseConditional createConditional(); } public abstract class BaseConditional : Conditional { public override BaseConditional createConditional() => new BrowserConditional(); /*BaseConditional createConditional() => throw UnsupportedError('Cannot create a conditional');*/ } /// A conditional for browser class BrowserConditional : BaseConditional { /// Returns [NetworkImage] if URI starts with http /// otherwise returns transparent image public override ImageProvider getProvider(string uri) { if ( uri.StartsWith("http") || uri.StartsWith("blob")) { return new NetworkImage(uri); } else { return new MemoryImage(ConditionalUtils.kTransparentImage); } } } public static class ConditionalUtils { /// Transparent image data public static byte[] kTransparentImage = nums.SelectMany(BitConverter.GetBytes).ToArray(); public static List nums = new List() { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D, 0x0A, 0x2D, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, }; } }