forked from flyerhq/flutter_chat_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace universal IO with conditional import
- Loading branch information
1 parent
9ecef93
commit 95a2a66
Showing
10 changed files
with
178 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.6.3 | ||
|
||
- Replace universal IO with conditional import | ||
|
||
## 0.6.2 | ||
|
||
- Update dependencies | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import 'conditional.dart'; | ||
|
||
/// The abstract base class for a conditional import feature. | ||
abstract class BaseConditional implements Conditional {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'dart:typed_data'; | ||
import 'package:flutter/material.dart'; | ||
import 'base_conditional.dart'; | ||
|
||
/// Create a [BrowserConditional]. | ||
/// | ||
/// Used from conditional imports, matches the definition in `conditional_stub.dart`. | ||
BaseConditional createConditional() => BrowserConditional(); | ||
|
||
/// A conditional for browser | ||
class BrowserConditional extends BaseConditional { | ||
/// Returns [NetworkImage] if URI starts with http | ||
/// otherwise returns transparent image | ||
@override | ||
ImageProvider getProvider(String uri) { | ||
if (uri.startsWith('http')) { | ||
return NetworkImage(uri); | ||
} else { | ||
return MemoryImage(kTransparentImage); | ||
} | ||
} | ||
} | ||
|
||
/// Transparent image data | ||
final kTransparentImage = Uint8List.fromList( | ||
<int>[ | ||
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, | ||
], | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'conditional_stub.dart' | ||
if (dart.library.io) 'io_conditional.dart' | ||
if (dart.library.html) 'browser_conditional.dart'; | ||
|
||
/// The abstract class for a conditional import feature. | ||
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. | ||
factory Conditional() => createConditional(); | ||
|
||
/// Returns an appropriate platform ImageProvider for specified URI | ||
ImageProvider getProvider(String uri); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'base_conditional.dart'; | ||
|
||
/// Implemented in `browser_conditional.dart` and `io_conditional.dart`. | ||
BaseConditional createConditional() => | ||
throw UnsupportedError('Cannot create a conditional'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:io'; | ||
import 'package:flutter/material.dart'; | ||
import 'base_conditional.dart'; | ||
|
||
/// Create a [IOConditional]. | ||
/// | ||
/// Used from conditional imports, matches the definition in `conditional_stub.dart`. | ||
BaseConditional createConditional() => IOConditional(); | ||
|
||
/// A conditional for anything but browser | ||
class IOConditional extends BaseConditional { | ||
/// Returns [NetworkImage] if URI starts with http | ||
/// otherwise uses IO to create File | ||
@override | ||
ImageProvider getProvider(String uri) { | ||
if (uri.startsWith('http')) { | ||
return NetworkImage(uri); | ||
} else { | ||
return FileImage(File(uri)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters