简体   繁体   中英

How do i add text to my floatingActionButton?

I am trying to add text to my floatingActionButton but I am unable to do so. How do I add the text to it not finding any way for it.

@override
Widget build(BuildContext context) {
  return Scaffold(
    floatingActionButton: FloatingActionButton(
      child: Icon(Icons.add),
      onPressed: () async {
        // when clicked on floating action button prompt to create user
        Navigator.pushReplacement(
          context,
          MaterialPageRoute(
            builder: (BuildContext context) => CreateUser(),
          ),
        );
      },
    ),
  );
}

You can use FloatingActionButton.extended to display Text and Icon in a FAB at once.

FloatingActionButton.extended(
  onPressed: () {
    // when clicked on floating action button prompt to create user
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(
        builder: (BuildContext context) => CreateUser(),
      ),
    );
  },
  label: Text('Label'),
  icon: Icon(Icons.add),
),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM