Flutter basics-020-FloatingActionButton

Flutter basics-020-FloatingActionButton

A floating button

Attributes
  • child: Icon(Icons.add),
  • onPressed: _onAdd,//Click to call the method
  • tooltip:'aaa',//Toast prompt after long press
  • foregroundColor: Colors.red,//Foreground color, cover color for some transparent places
  • backgroundColor: Colors.red[200],//Background color
  • focusColor: Colors.blue,//???
  • hoverColor: Colors.blue,//???
  • hoverElevation: 10,//???
  • focusElevation: 10,//???
  • disabledElevation: 10,//button's change size when disabled
  • elevation: 10,//Shadow size in normal state
  • highlightElevation: 20,//The size of the shadow in the highlight state
  • mini: false,//Whether it is the smallest, the default is false
  • shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),//set the shape
  • clipBehavior: Clip.antiAliasWithSaveLayer,//???
  • isExtended: true,//???
  • materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,//???

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
       //
        title: Text("App Name"),
        actions: <Widget>[
         //
          IconButton(icon: Icon(Icons.share), onPressed: () {}),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
       // 
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
          BottomNavigationBarItem(
              icon: Icon(Icons.business), title: Text('Business')),
          BottomNavigationBarItem(
              icon: Icon(Icons.school), title: Text('School')),
        ],
        currentIndex: _selectedIndex,
        fixedColor: Colors.blue,
        onTap: _onItemTapped,
      ),
      floatingActionButton: FloatingActionButton(
         //
          child: Icon(Icons.add),
          onPressed: _onAdd,// 
        tooltip: 'aaa',// toast 
        foregroundColor: Colors.red,//
        backgroundColor: Colors.red[200],//
        focusColor: Colors.blue,//???
        hoverColor: Colors.blue,//???
        hoverElevation: 10,//???
        focusElevation: 10,//???
        disabledElevation: 10,//button 
        elevation: 10,//
        highlightElevation: 20,// 
        mini: false,// false
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),// 
        clipBehavior: Clip.antiAliasWithSaveLayer,//???
        isExtended: true,//???
        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,//???
      ),
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  void _onAdd() {
    setState(() {
      _selectedIndex++;
      if (_selectedIndex > 2) {
        _selectedIndex = 0;
      }
    });
  }
}