Skip to content

Commit e02ef11

Browse files
committed
Convert preview to stream-based, fix keyboard layout distortion, update app icon
1 parent 9641eb7 commit e02ef11

16 files changed

+435
-354
lines changed

assets/512w/ic_foreground.png

-6.48 KB
Binary file not shown.

assets/512w/ic_launcher.png

-11.1 KB
Binary file not shown.

assets/ic_foreground.png

2.21 KB
Loading

lib/data/streams/stats_stream.dart

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'dart:async';
2+
3+
import 'package:underdog/data/models/stats.dart';
4+
5+
class StatsStream {
6+
final StreamController<Stats> _controller = StreamController<Stats>();
7+
8+
void updateStats(Stats stats) {
9+
_controller.sink.add(stats);
10+
}
11+
12+
Stream<Stats> get value => _controller.stream;
13+
}

lib/pages/home_page.dart

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
108108
const Duration(seconds: 3), _updateUserMarker);
109109
_initializeUserMarker();
110110
_animateToUserLocation();
111-
model.getStats();
112111
},
113112
markers: Set<Marker>.of(markers.values),
114113
),

lib/pages/login_page.dart

-11
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,11 @@ class _LoginPageState extends State<LoginPage>
3636
child: Consumer<LoginModel>(
3737
builder: (BuildContext context, LoginModel model, Widget child) {
3838
final bool isBusy = model.state == PageState.Busy;
39-
const double radius = 56;
4039

4140
return Scaffold(
4241
backgroundColor: Colors.white,
4342
body: Stack(
4443
children: <Widget>[
45-
// Material(
46-
// color: Colors.white,
47-
// child: Container(
48-
// height: MediaQuery.of(context).size.height * 0.8,
49-
// width: double.infinity,
50-
// ),
51-
// shape: RoundedRectangleBorder(
52-
// borderRadius: BorderRadius.circular(radius),
53-
// side: BorderSide(color: Colors.white12)),
54-
// ),
5544
Center(
5645
child: Container(
5746
constraints: const BoxConstraints(maxWidth: 256),

lib/pages/register_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class _RegisterPageState extends State<RegisterPage>
6161
tag: HeroTag.SIGN_UP,
6262
child: Center(
6363
child: Container(
64-
constraints: const BoxConstraints(maxWidth: 280),
64+
constraints: const BoxConstraints(maxWidth: 300),
6565
child: Form(
6666
key: _formKey,
6767
child: SingleChildScrollView(

lib/pages/reports_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _ReportsPageState extends State<ReportsPage>
3434
Material(
3535
color: Colors.white,
3636
child: Container(
37-
height: MediaQuery.of(context).size.height * 0.94,
37+
height: MediaQuery.of(context).size.height * 0.93,
3838
width: double.infinity,
3939
),
4040
shape: RoundedRectangleBorder(

lib/pages/submit_report_page.dart

+177-173
Large diffs are not rendered by default.

lib/pages/submit_rescue_page.dart

+153-145
Large diffs are not rendered by default.

lib/pages/view_report_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ViewReportPage extends StatelessWidget {
113113
)));
114114
},
115115
child: Hero(
116-
tag: HeroTag.REPORT_IMAGE_,
116+
tag: HeroTag.REPORT_IMAGE_ + report.uid,
117117
child: Material(
118118
shape: RoundedRectangleBorder(
119119
side: BorderSide(color: Colors.black12)),

lib/pages/view_rescue_page.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,12 @@ class _ViewRescuePageState extends State<ViewRescuePage> {
9696
context,
9797
SlideLeftPageRoute<void>(
9898
page: ViewImagePage(
99-
url: model.rescue.imageUrl,
99+
// url: model.rescue.imageUrl,
100100
uid: widget.report.uid,
101101
)));
102102
},
103103
child: Hero(
104-
tag: HeroTag.REPORT_IMAGE_ +
105-
widget.report.uid,
104+
tag: HeroTag.REPORT_IMAGE_,
106105
child: Material(
107106
borderOnForeground: true,
108107
shape: RoundedRectangleBorder(

lib/services/reports_database_service.dart

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
import 'dart:async';
2+
13
import 'package:firebase_database/firebase_database.dart';
24
import 'package:underdog/data/models/report.dart';
35
import 'package:underdog/data/models/stats.dart';
6+
import 'package:underdog/data/streams/stats_stream.dart';
47

58
class ReportsDatabaseService {
69
ReportsDatabaseService() {
710
FirebaseDatabase.instance.setPersistenceEnabled(true);
811
}
912

13+
StatsStream _statsStream;
14+
StreamSubscription<Event> _statsStreamSubscription;
15+
1016
final DatabaseReference _databaseReference =
1117
FirebaseDatabase.instance.reference().child('reports');
1218

@@ -28,12 +34,18 @@ class ReportsDatabaseService {
2834
await _databaseReference.child(uid).child('is_rescued').set(isRescued);
2935
}
3036

31-
Future<Stats> getStats() async {
32-
final Map<dynamic, dynamic> reportsMap =
33-
(await getUnrescued().once()).value;
34-
final Map<dynamic, dynamic> rescuesMap = (await getRescued().once()).value;
37+
Stream<Stats> watchStats() {
38+
_statsStreamSubscription =
39+
_databaseReference.onChildChanged.listen((_) async {
40+
final Map<dynamic, dynamic> reportsMap =
41+
(await getUnrescued().once()).value;
42+
final Map<dynamic, dynamic> rescuesMap =
43+
(await getRescued().once()).value;
44+
45+
_statsStream.updateStats(Stats(reportsMap.length, rescuesMap.length));
46+
});
3547

36-
return Stats(reportsMap.length, rescuesMap.length);
48+
return _statsStream.value;
3749
}
3850

3951
Query getRescued() {

lib/viewmodels/home_model.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ class HomeModel extends ChangeNotifier {
6060
return _reports;
6161
}
6262

63-
Future<void> getStats() async {
64-
_stats = await _reportsDatabaseService.getStats();
65-
notifyListeners();
63+
Stream<Stats> watchStats() {
64+
return _reportsDatabaseService.watchStats();
6665
}
6766

6867
void selectReport(Report report) {

lib/widgets/stats_overview.dart

+67-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
3+
import 'package:underdog/data/models/stats.dart';
34
import 'package:underdog/underdog_theme.dart';
45
import 'package:underdog/viewmodels/home_model.dart';
56

@@ -8,16 +9,15 @@ class StatsOverview extends StatelessWidget {
89

910
@override
1011
Widget build(BuildContext context) {
11-
final TextStyle countStyle = TextStyle(
12-
// fontWeight: FontWeight.bold,
13-
fontSize: 28,
14-
color: Theme.of(context).accentColor);
12+
final TextStyle countStyle =
13+
TextStyle(fontSize: 28, color: Theme.of(context).accentColor);
1514
final TextStyle labelStyle =
1615
TextStyle(fontWeight: FontWeight.bold, color: UnderdogTheme.darkTeal);
1716

18-
return Consumer<HomeModel>(
19-
builder: (BuildContext context, HomeModel model, Widget child) {
20-
if (model.stats == null) {
17+
return StreamBuilder<Stats>(
18+
stream: Provider.of<HomeModel>(context).watchStats(),
19+
builder: (BuildContext context, AsyncSnapshot<Stats> snapshot) {
20+
if (!snapshot.hasData) {
2121
return const Padding(
2222
padding: EdgeInsets.all(16.0),
2323
child: Center(
@@ -45,7 +45,7 @@ class StatsOverview extends StatelessWidget {
4545
Column(
4646
children: <Widget>[
4747
Text(
48-
'${model.stats.reportCount}',
48+
'${snapshot.data.reportCount}',
4949
style: countStyle,
5050
),
5151
Text(
@@ -57,7 +57,7 @@ class StatsOverview extends StatelessWidget {
5757
Column(
5858
children: <Widget>[
5959
Text(
60-
'${model.stats.rescueCount}',
60+
'${snapshot.data.rescueCount}',
6161
style: countStyle,
6262
),
6363
Text('Rescues', style: labelStyle)
@@ -72,6 +72,64 @@ class StatsOverview extends StatelessWidget {
7272
}
7373
},
7474
);
75+
76+
// return Consumer<HomeModel>(
77+
// builder: (BuildContext context, HomeModel model, Widget child) {
78+
// if (model.stats == null) {
79+
// return const Padding(
80+
// padding: EdgeInsets.all(16.0),
81+
// child: Center(
82+
// child: CircularProgressIndicator(),
83+
// ),
84+
// );
85+
// } else {
86+
// return Padding(
87+
// padding: const EdgeInsets.all(8.0),
88+
// child: Column(
89+
// mainAxisAlignment: MainAxisAlignment.center,
90+
// children: <Widget>[
91+
// Text(
92+
// '${_createGreetingString()}',
93+
// style: TextStyle(fontSize: 24, color: UnderdogTheme.teal),
94+
// ),
95+
// Text(
96+
// 'as of the moment, there are',
97+
// style: TextStyle(fontSize: 14, color: UnderdogTheme.darkTeal),
98+
// ),
99+
// const SizedBox(height: 8),
100+
// Row(
101+
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
102+
// children: <Widget>[
103+
// Column(
104+
// children: <Widget>[
105+
// Text(
106+
// '${model.stats.reportCount}',
107+
// style: countStyle,
108+
// ),
109+
// Text(
110+
// 'Reports',
111+
// style: labelStyle,
112+
// )
113+
// ],
114+
// ),
115+
// Column(
116+
// children: <Widget>[
117+
// Text(
118+
// '${model.stats.rescueCount}',
119+
// style: countStyle,
120+
// ),
121+
// Text('Rescues', style: labelStyle)
122+
// ],
123+
// ),
124+
// ],
125+
// ),
126+
// const SizedBox(height: 8),
127+
// ],
128+
// ),
129+
// );
130+
// }
131+
// },
132+
// );
75133
}
76134

77135
String _createGreetingString() {

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ flutter_icons:
5656
android: "launcher_icon"
5757
ios: true
5858
image_path: "assets/ic_launcher.png"
59-
adaptive_icon_background: "#EE4266"
59+
adaptive_icon_background: "#16BAC6"
6060
adaptive_icon_foreground: "assets/ic_foreground.png"
6161

6262

0 commit comments

Comments
 (0)