111 lines
3.1 KiB
Dart
111 lines
3.1 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:anyway/constants.dart';
|
|
import 'package:anyway/structs/trip.dart';
|
|
import 'package:auto_size_text/auto_size_text.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class Greeter extends StatefulWidget {
|
|
final Trip trip;
|
|
|
|
Greeter({
|
|
required this.trip,
|
|
});
|
|
|
|
@override
|
|
State<Greeter> createState() => _GreeterState();
|
|
}
|
|
|
|
|
|
class _GreeterState extends State<Greeter> {
|
|
|
|
Widget greeterBuilder (BuildContext context, Widget? child) {
|
|
final Shader textGradient = APP_GRADIENT.createShader(Rect.fromLTWH(0.0, 0.0, 200.0, 70.0));
|
|
TextStyle greeterStyle = TextStyle(
|
|
foreground: Paint()..shader = textGradient,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 26
|
|
);
|
|
|
|
Widget topGreeter;
|
|
|
|
if (widget.trip.uuid != 'pending') {
|
|
topGreeter = FutureBuilder(
|
|
future: widget.trip.cityName,
|
|
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
|
if (snapshot.hasData) {
|
|
return AutoSizeText(
|
|
maxLines: 1,
|
|
'Welcome to ${snapshot.data}!',
|
|
style: greeterStyle
|
|
);
|
|
} else if (snapshot.hasError) {
|
|
log('Error while fetching city name');
|
|
return AutoSizeText(
|
|
maxLines: 1,
|
|
'Welcome to your trip!',
|
|
style: greeterStyle
|
|
);
|
|
} else {
|
|
return AutoSizeText(
|
|
maxLines: 1,
|
|
'Welcome to ...',
|
|
style: greeterStyle
|
|
);
|
|
}
|
|
}
|
|
);
|
|
} else {
|
|
// still awaiting the trip
|
|
// We can hopefully infer the city name from the cityName future
|
|
// Show a linear loader at the bottom and an info message above
|
|
topGreeter = Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
FutureBuilder(
|
|
future: widget.trip.cityName,
|
|
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
|
if (snapshot.hasData) {
|
|
return AutoSizeText(
|
|
maxLines: 1,
|
|
'Generating your trip to ${snapshot.data}...',
|
|
style: greeterStyle
|
|
);
|
|
} else if (snapshot.hasError) {
|
|
// the exact error is shown in the central part of the trip overview. No need to show it here
|
|
return AutoSizeText(
|
|
maxLines: 1,
|
|
'Error while loading trip.',
|
|
style: greeterStyle
|
|
);
|
|
}
|
|
return AutoSizeText(
|
|
maxLines: 1,
|
|
'Generating your trip...',
|
|
style: greeterStyle
|
|
);
|
|
}
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.all(5),
|
|
child: const LinearProgressIndicator()
|
|
)
|
|
]
|
|
);
|
|
}
|
|
|
|
return Center(
|
|
child: topGreeter,
|
|
);
|
|
}
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: widget.trip,
|
|
builder: greeterBuilder,
|
|
);
|
|
}
|
|
} |