flutter_demo_gps/lib/widgets/gps_title_widget_bloc.dart

26 lines
832 B
Dart
Raw Normal View History

2022-10-18 15:07:13 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:gps/blocs/bloc_provider.dart';
import 'package:gps/blocs/gps_bloc.dart';
class GpsTitleWidgetBloc extends StatelessWidget {
const GpsTitleWidgetBloc({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final GpsBloc bloc = BlocProvider.of<GpsBloc>(context);
return StreamBuilder(
stream: bloc.stateOut,
initialData: GpsBlocState.notRecording,
builder: (BuildContext context, AsyncSnapshot<GpsBlocState> snapshot) {
String title = AppLocalizations.of(context)!.appName;
final state =
(snapshot.data == GpsBlocState.recording) ? "- recording" : "";
return Text("$title $state");
});
}
}