87 lines
2.1 KiB
Dart
87 lines
2.1 KiB
Dart
import 'package:anyway/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);
|
|
Widget topGreeter;
|
|
if (snapshot.hasData) {
|
|
topGreeter = Padding(
|
|
padding: const EdgeInsets.only(top: 20, bottom: 20),
|
|
child: Text(
|
|
'Welcome to ${snapshot.data?.cityName}!',
|
|
style: TextStyle(color: theme.primaryColor, fontWeight: FontWeight.bold, fontSize: 24),
|
|
)
|
|
);
|
|
} else if (snapshot.hasError) {
|
|
topGreeter = const Padding(
|
|
padding: EdgeInsets.only(top: 20, bottom: 20),
|
|
child: Text('Error while fetching trip')
|
|
);
|
|
} else {
|
|
// still awaiting the cityname
|
|
// Show a linear loader at the bottom and an info message above
|
|
topGreeter = Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 20, bottom: 20),
|
|
child: const Text('Generating your trip...', style: TextStyle(fontSize: 20),)
|
|
),
|
|
const LinearProgressIndicator()
|
|
]
|
|
);
|
|
}
|
|
|
|
|
|
|
|
if (widget.standalone) {
|
|
return Center(
|
|
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,
|
|
);
|
|
}
|
|
} |