73 lines
1.7 KiB
Dart
73 lines
1.7 KiB
Dart
import 'package:fast_network_navigation/structs/trip.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class Greeter extends StatefulWidget {
|
|
final Future<Trip> trip;
|
|
final bool standalone;
|
|
|
|
Greeter({
|
|
required this.standalone,
|
|
required this.trip
|
|
});
|
|
|
|
@override
|
|
State<Greeter> createState() => _GreeterState();
|
|
}
|
|
|
|
|
|
|
|
class _GreeterState extends State<Greeter> {
|
|
Widget greeterBuild (BuildContext context, AsyncSnapshot<Trip> snapshot) {
|
|
ThemeData theme = Theme.of(context);
|
|
String cityName = "";
|
|
if (snapshot.hasData) {
|
|
cityName = snapshot.data?.cityName ?? '...';
|
|
} else if (snapshot.hasError) {
|
|
cityName = "error";
|
|
} else { // still awaiting the cityname
|
|
cityName = "...";
|
|
}
|
|
|
|
Widget topGreeter = Text(
|
|
'Welcome to $cityName!',
|
|
style: TextStyle(color: theme.primaryColor, fontWeight: FontWeight.bold, fontSize: 24),
|
|
);
|
|
|
|
if (widget.standalone) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(top: 24.0),
|
|
child: topGreeter,
|
|
),
|
|
);
|
|
} else {
|
|
return Center(
|
|
child: Column(
|
|
children: [
|
|
Padding(padding: EdgeInsets.only(top: 24.0)),
|
|
topGreeter,
|
|
bottomGreeter,
|
|
Padding(padding: EdgeInsets.only(bottom: 24.0)),
|
|
],
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget bottomGreeter = const Text(
|
|
"Busy day ahead? Here is how to make the most of it!",
|
|
style: TextStyle(color: Colors.black, fontSize: 18),
|
|
textAlign: TextAlign.center,
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder(
|
|
future: widget.trip,
|
|
builder: greeterBuild,
|
|
);
|
|
}
|
|
} |