import 'package:touch_demonstrator/src/blocs/BlocProvider.dart'; import 'package:touch_demonstrator/pages/DebugPage.dart'; import 'package:flutter/material.dart'; import 'package:touch_demonstrator/src/blocs/bluetoothBloc.dart'; import 'package:touch_demonstrator/src/blocs/debugCounterBloc.dart'; Widget buildAppBarPageTouchPoints(BuildContext context) { void _pageRouteDebugView() { print('Debug button pressed'); Navigator.push( context, MaterialPageRoute(builder: (context) => DebugView())); } IconButton _buildDebugIconButton() { return IconButton( key: Key('debugButton'), icon: Icon(Icons.bug_report), onPressed: _pageRouteDebugView, ); } StreamBuilder titleAppBar() { final bBloc = BlocProvider.of(context).bluetoothBlocGetter; var appBarText; return StreamBuilder( stream: bBloc.isConnected$, initialData: false, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasData) { snapshot.data ? appBarText = 'Connected' : appBarText = 'Disconnected'; return AnimatedSwitcher( duration: Duration(milliseconds: 300), transitionBuilder: (Widget child, Animation opacity) { return FadeTransition(child: child, opacity: opacity); }, child: Text( '$appBarText', key: ValueKey(appBarText), textDirection: TextDirection.ltr, ), ); } else return Text('Disconnected'); }); } List actionsAppBar() { final debugBloc = BlocProvider.of(context).debugBlocGetter; return [ StreamBuilder( stream: debugBloc.debugEnabledStatus$, initialData: false, builder: (BuildContext context, AsyncSnapshot snapshotDebug) { if (snapshotDebug.hasData) { return snapshotDebug.data ? _buildDebugIconButton() : Container(); } else return Container(); }, ), ]; } return AppBar( title: titleAppBar(), actions: actionsAppBar(), ); }