test_bed.dart 1.22 KB
Newer Older
1
import 'dart:ui';
2

3 4 5 6
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
7
import 'package:flutter_sprites/flutter_sprites.dart';
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

AssetBundle _initBundle() {
  if (rootBundle != null)
    return rootBundle;
  return new NetworkAssetBundle(Uri.base);
}

final AssetBundle _bundle = _initBundle();

ImageMap _images;
SpriteSheet _spriteSheet;
TestBedApp _app;

main() async {
  _images = new ImageMap(_bundle);

Hixie's avatar
Hixie committed
24
  await _images.load(<String>[
25 26 27 28 29 30 31 32 33 34
    'assets/sprites.png'
  ]);

  String json = await _bundle.loadString('assets/sprites.json');
  _spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);

  _app = new TestBedApp();
  runApp(_app);
}

Adam Barth's avatar
Adam Barth committed
35
class TestBedApp extends MaterialApp {
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

  Widget build() {
    ThemeData theme = new ThemeData(
      brightness: ThemeBrightness.light,
      primarySwatch: Colors.purple
    );

    return new Theme(
      data: theme,
      child: new Title(
        title: 'Test Bed',
        child: new SpriteWidget(
          new TestBed(),
          SpriteBoxTransformMode.letterbox
        )
      )
    );
  }
}

class TestBed extends NodeWithSize {
Hixie's avatar
Hixie committed
57
  TestBed() : super(new Size(1024.0, 1024.0));
58
}