cwtch-ui/lib/main_test.dart

75 lines
2.2 KiB
Dart
Raw Normal View History

import 'package:cwtch/themes/cwtch.dart';
2021-06-24 23:10:45 +00:00
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:cwtch/errorHandler.dart';
import 'package:cwtch/settings.dart';
import 'package:glob/list_local_fs.dart';
import 'config.dart';
2021-06-24 23:10:45 +00:00
import 'licenses.dart';
import 'main.dart';
2021-12-07 01:40:10 +00:00
import 'themes/opaque.dart';
2021-06-24 23:10:45 +00:00
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import "package:flutter_driver/driver_extension.dart";
2021-06-24 23:10:45 +00:00
import 'package:flutter_test/flutter_test.dart';
import 'package:glob/glob.dart';
var globalSettings = Settings(Locale("en", ''), CwtchDark());
2021-06-24 23:10:45 +00:00
var globalErrorHandler = ErrorHandler();
Future<void> main() async {
enableFlutterDriverExtension();
print("Cwtch version: ${EnvironmentConfig.BUILD_VER} built on: ${EnvironmentConfig.BUILD_DATE}");
WidgetsFlutterBinding.ensureInitialized();
print("runApp()");
2021-06-24 23:10:45 +00:00
LicenseRegistry.addLicense(() => licenses());
return DiskAssetBundle.loadGlob(['profiles/*.png']).then((assetBundle) {
2021-06-24 23:10:45 +00:00
runApp(DefaultAssetBundle(
bundle: assetBundle,
child: Flwtch(),
));
});
}
class DiskAssetBundle extends CachingAssetBundle {
static const _assetManifestDotJson = 'AssetManifest.json';
/// Creates a [DiskAssetBundle] by loading [globs] of assets under `assets/`.
static Future<AssetBundle> loadGlob(
Iterable<String> globs, {
String from = 'assets',
}) async {
final cache = <String, ByteData>{};
for (final pattern in globs) {
await for (final path in Glob(pattern).list(root: from)) {
if (path is File) {
final bytes = await (path as File).readAsBytes() /* as Uint8List*/;
cache[path.path] = ByteData.view(bytes.buffer);
}
}
}
final manifest = <String, List<String>>{};
cache.forEach((key, _) {
manifest[key] = [key];
});
cache[_assetManifestDotJson] = ByteData.view(
Uint8List.fromList(jsonEncode(manifest).codeUnits).buffer,
);
return DiskAssetBundle._(cache);
}
final Map<String, ByteData> _cache;
DiskAssetBundle._(this._cache);
@override
Future<ByteData> load(String key) async {
return _cache[key]!;
}
}