feat: wire the logo in as app icon and splash
This commit is contained in:
parent
dcb70a93d1
commit
8426818712
14 changed files with 129 additions and 21 deletions
50
app/tool/generate_icons.dart
Normal file
50
app/tool/generate_icons.dart
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import 'dart:io';
|
||||
import 'dart:ui' as ui show ImageByteFormat, PictureRecorder;
|
||||
|
||||
|
||||
import 'package:flutter/widgets.dart' show Canvas;
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// Rasterizes `assets/logo.svg` into the PNGs the platforms want: the
|
||||
/// Android launcher icons at every density, the splash logo, and the
|
||||
/// bundled logo the Linux window icon loads. Run with:
|
||||
///
|
||||
/// flutter test tool/generate_icons.dart
|
||||
///
|
||||
/// The committed PNGs are the product; this exists so a new logo can be
|
||||
/// dropped in as the SVG and every platform follows in one run.
|
||||
const sizes = {
|
||||
'android/app/src/main/res/mipmap-mdpi/ic_launcher.png': 48,
|
||||
'android/app/src/main/res/mipmap-hdpi/ic_launcher.png': 72,
|
||||
'android/app/src/main/res/mipmap-xhdpi/ic_launcher.png': 96,
|
||||
'android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png': 144,
|
||||
'android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png': 192,
|
||||
'android/app/src/main/res/drawable-nodpi/splash_logo.png': 432,
|
||||
'assets/logo.png': 256,
|
||||
};
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('rasterizes the logo for every platform', () async {
|
||||
final svg = File('assets/logo.svg').readAsStringSync();
|
||||
final info = await vg.loadPicture(SvgStringLoader(svg), null);
|
||||
|
||||
for (final entry in sizes.entries) {
|
||||
final size = entry.value;
|
||||
final recorder = ui.PictureRecorder();
|
||||
final canvas = Canvas(recorder);
|
||||
// The logo is square, so one scale fits both axes.
|
||||
canvas.scale(size / info.size.width, size / info.size.height);
|
||||
canvas.drawPicture(info.picture);
|
||||
final image = await recorder.endRecording().toImage(size, size);
|
||||
final bytes = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
final file = File(entry.key);
|
||||
await file.parent.create(recursive: true);
|
||||
await file.writeAsBytes(bytes!.buffer.asUint8List());
|
||||
// ignore: avoid_print
|
||||
print('wrote ${file.path} (${size}x$size)');
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue