flutter_demo_gps/lib/widgets/gps_buttons_widget_bloc.dart

34 lines
1.1 KiB
Dart
Raw Permalink Normal View History

2022-10-18 15:07:13 +02:00
import 'package:flutter/material.dart';
import 'package:gps/blocs/bloc_provider.dart';
import 'package:gps/blocs/gps_bloc.dart';
class GpsButtonsWidgetBloc extends StatelessWidget {
const GpsButtonsWidgetBloc({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final GpsBloc bloc = BlocProvider.of<GpsBloc>(context);
return Row(
children: [
StreamBuilder<GpsBlocState>(
stream: bloc.stateOut,
initialData: GpsBlocState.notRecording,
builder: (BuildContext context,
AsyncSnapshot<GpsBlocState> snapshot) {
return IconButton(
onPressed: () => bloc.actionIn.add(GpsBlocAction.toggleRecording),
icon: Icon(snapshot.data == GpsBlocState.recording
? Icons.stop
: Icons.fiber_manual_record),
);
}),
IconButton(
onPressed: () => bloc.actionIn.add(GpsBlocAction.save),
icon: const Icon(Icons.save),
)
],
);
}
}