|
import 'dart:async'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
void main() => runApp(MyApp()); |
|
|
|
Stream<bool> get isFABVisible => _isFABVisibleController.stream; |
|
final _isFABVisibleController = StreamController<bool>.broadcast(); |
|
|
|
class MyApp extends StatelessWidget { |
|
// This widget is the root of your application. |
|
@override |
|
Widget build(BuildContext context) { |
|
return MaterialApp( |
|
title: 'Flutter Demo', |
|
theme: ThemeData( |
|
primarySwatch: Colors.blue, |
|
), |
|
home: MyHomePage(title: 'Flutter Demo Home Page'), |
|
); |
|
} |
|
} |
|
|
|
class MyHomePage extends StatefulWidget { |
|
MyHomePage({Key key, this.title}) : super(key: key); |
|
final String title; |
|
|
|
@override |
|
_MyHomePageState createState() => _MyHomePageState(); |
|
} |
|
|
|
class _MyHomePageState extends State<MyHomePage> { |
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: AppBar(title: Text(widget.title)), |
|
body: Center( |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: <Widget>[ |
|
RaisedButton( |
|
child: Text("Push new page"), |
|
onPressed: () { |
|
Navigator.push( |
|
context, |
|
MaterialPageRoute(builder: (context) => NewPage()), |
|
); |
|
}, |
|
), |
|
], |
|
), |
|
), |
|
floatingActionButton: FloatingActionButton( |
|
onPressed: () {}, |
|
child: Icon(Icons.add), |
|
), |
|
); |
|
} |
|
} |
|
|
|
class NewPage extends StatelessWidget { |
|
const NewPage({Key key}) : super(key: key); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return StreamBuilder<bool>( |
|
stream: isFABVisible, |
|
initialData: true, |
|
builder: (context, snapshot) { |
|
return Scaffold( |
|
appBar: AppBar(title: Text('Next page')), |
|
body: Center( |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: <Widget>[ |
|
RaisedButton( |
|
onPressed: () => _isFABVisibleController.add(false), |
|
child: Text("Press to make FAB disappear"), |
|
), |
|
RaisedButton( |
|
onPressed: () => _isFABVisibleController.add(true), |
|
child: Text("Press to make FAB reappear"), |
|
), |
|
], |
|
), |
|
), |
|
floatingActionButton: snapshot.data |
|
? FloatingActionButton( |
|
onPressed: () {}, |
|
child: Icon(Icons.remove_circle), |
|
) |
|
: null, |
|
); |
|
}, |
|
); |
|
} |
|
} |