croupier: AssetImage and UTF8.encode("now")
In order to have images load more quickly and consistently, I have
moved from NetworkImage to AssetImage.
Alongside this, we can cut down on an RPC if we switch from
await db.getResumeMarker to UTF8.encode("now"). This is a special
resume marker that basically acts the same way.
Change-Id: I5868779cb9f16ce6cc2d17addcb888bf7b23b673
diff --git a/lib/components/card.dart b/lib/components/card.dart
index cc71917..e3dbd89 100644
--- a/lib/components/card.dart
+++ b/lib/components/card.dart
@@ -121,21 +121,20 @@
widgets.Widget image = new widgets.Opacity(
opacity: config.visible ? 1.0 : 0.0,
child: new widgets.Transform(
- child: _imageFromCard(config.card, config.faceUp),
+ child: _imageFromCard(config.card, config.faceUp, config.width, config.height),
transform:
new vector_math.Matrix4.identity().rotateZ(config.rotation),
alignment: new FractionalOffset(0.5, 0.5)));
- return new widgets.Container(
- width: config.width, height: config.height, child: image);
+ return image;
}
}
-widgets.Widget _imageFromCard(logic_card.Card c, bool faceUp) {
+widgets.Widget _imageFromCard(logic_card.Card c, bool faceUp, double width, double height) {
// TODO(alexfandrianto): Instead of 'default', what if we were told which theme to use?
String imageName =
"images/default/${c.deck}/${faceUp ? 'up' : 'down'}/${c.identifier}.png";
- return new widgets.NetworkImage(src: imageName);
+ return new widgets.AssetImage(name: imageName, width: width, height: height);
}
class _ZCardState extends widgets.State<ZCard> {
@@ -232,20 +231,16 @@
widgets.Widget build(widgets.BuildContext context) {
widgets.Widget image = new widgets.Transform(
- child: _imageFromCard(config.card, config.faceUp),
+ child: _imageFromCard(config.card, config.faceUp, config.width, config.height),
transform: new vector_math.Matrix4.identity().rotateZ(config.rotation),
alignment: new FractionalOffset(0.5, 0.5));
- // Size the card appropriately.
- widgets.Widget containedCard = new widgets.Container(
- width: config.width, height: config.height, child: image);
-
// Set up the slide transition.
// During animation, we must ignore all events.
widgets.Widget retWidget = new widgets.SlideTransition(
performance: _performance.view,
position: _performance.variable,
- child: containedCard);
+ child: image);
return retWidget;
}
diff --git a/lib/components/card_collection.dart b/lib/components/card_collection.dart
index 480aa3d..2248fba 100644
--- a/lib/components/card_collection.dart
+++ b/lib/components/card_collection.dart
@@ -190,11 +190,9 @@
child: new Center(
child: new Opacity(
opacity: 0.45,
- child: new Container(
- height: config.heightCard,
- child: emptyBackgroundImage == ""
- ? null
- : new NetworkImage(src: emptyBackgroundImage)))));
+ child: emptyBackgroundImage == ""
+ ? null
+ : new AssetImage(name: emptyBackgroundImage, fit: ImageFit.scaleDown, height: config.heightCard))));
}
double w = config.width ?? config.widthCard * 5;
diff --git a/lib/components/croupier_profile.dart b/lib/components/croupier_profile.dart
index cf3de40..d8fe840 100644
--- a/lib/components/croupier_profile.dart
+++ b/lib/components/croupier_profile.dart
@@ -15,6 +15,6 @@
decoration:
new BoxDecoration(backgroundColor: new Color(settings.color)),
child: new Column(
- [new NetworkImage(src: CroupierSettings.makeAvatarUrl(settings.avatar)), new Text(settings.name)]));
+ [new AssetImage(name: CroupierSettings.makeAvatarUrl(settings.avatar)), new Text(settings.name)]));
}
}
diff --git a/lib/components/croupier_settings.dart b/lib/components/croupier_settings.dart
index d34bc2e..fe6f194 100644
--- a/lib/components/croupier_settings.dart
+++ b/lib/components/croupier_settings.dart
@@ -61,7 +61,7 @@
}
Widget _makeImageButton(String url, NoArgCb cb) {
- return new FlatButton(child: new NetworkImage(src: CroupierSettings.makeAvatarUrl(url)), onPressed: cb);
+ return new FlatButton(child: new AssetImage(name: CroupierSettings.makeAvatarUrl(url)), onPressed: cb);
}
Widget build(BuildContext context) {
@@ -70,7 +70,7 @@
w.add(_makeButtonRow(
colorKey, _makeColoredRectangle(config.settings.color, "", null)));
w.add(_makeButtonRow(
- avatarKey, new NetworkImage(src: CroupierSettings.makeAvatarUrl(config.settings.avatar))));
+ avatarKey, new AssetImage(name: CroupierSettings.makeAvatarUrl(config.settings.avatar))));
w.add(new FlatButton(child: new Text("Return"), onPressed: config.backCb));
return new Column(w);
diff --git a/lib/src/syncbase/log_writer.dart b/lib/src/syncbase/log_writer.dart
index e7f6b9f..90fedc3 100644
--- a/lib/src/syncbase/log_writer.dart
+++ b/lib/src/syncbase/log_writer.dart
@@ -81,7 +81,7 @@
// Start to watch the stream.
Stream<WatchChange> watchStream =
- db.watch(tbName, this.logPrefix, await db.getResumeMarker());
+ db.watch(tbName, this.logPrefix, UTF8.encode("now"));
_startWatch(watchStream); // Don't wait for this future.
}
diff --git a/lib/src/syncbase/settings_manager.dart b/lib/src/syncbase/settings_manager.dart
index dbfed6f..66fccee 100644
--- a/lib/src/syncbase/settings_manager.dart
+++ b/lib/src/syncbase/settings_manager.dart
@@ -60,7 +60,7 @@
// Start to watch the stream for the shared settings table.
Stream<sc.WatchChange> watchStream = db.watch(util.tableNameSettings,
- _settingsWatchSyncPrefix, await db.getResumeMarker());
+ _settingsWatchSyncPrefix, UTF8.encode("now"));
_startWatchSettings(watchStream); // Don't wait for this future.
_loadSettings(tb); // Don't wait for this future.
}
@@ -181,7 +181,7 @@
// Watch for the players in the game.
Stream<sc.WatchChange> watchStream = db.watch(util.tableNameGames,
- util.syncgamePrefix(gameID) + "/players", await db.getResumeMarker());
+ util.syncgamePrefix(gameID) + "/players", UTF8.encode("now"));
_startWatchPlayers(watchStream); // Don't wait for this future.
print("Now writing to some rows of ${gameID}");
@@ -214,7 +214,7 @@
// Watch for the players in the game.
Stream<sc.WatchChange> watchStream = db.watch(util.tableNameGames,
- util.syncgamePrefix(gameID) + "/players", await db.getResumeMarker());
+ util.syncgamePrefix(gameID) + "/players", UTF8.encode("now"));
_startWatchPlayers(watchStream); // Don't wait for this future.
// Also write yourself to the table as player |NUM_PLAYERS - 1|