Created
October 13, 2024 19:47
-
-
Save sigmapie8/c3bc8cce25f7fa36303fa6a015e4c00c to your computer and use it in GitHub Desktop.
Badge class examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| runApp(const MainApp()); | |
| } | |
| class MainApp extends StatelessWidget { | |
| const MainApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: Scaffold( | |
| body: SafeArea( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.start, | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| children: [ | |
| const SizedBox( | |
| height: 10, | |
| ), | |
| Badge.count( | |
| count: 42, | |
| child: const Icon( | |
| Icons.notifications, | |
| size: 30.0, | |
| ), | |
| ), | |
| const SizedBox( | |
| height: 10, | |
| ), | |
| Container( | |
| color: Colors.blueAccent.withOpacity(0.1), | |
| margin: const EdgeInsets.all(16.0), | |
| child: const Badge( | |
| child: ListTile( | |
| title: Text("Unread notification"), | |
| ), | |
| ), | |
| ), | |
| const SizedBox( | |
| height: 10, | |
| ), | |
| const Badge( | |
| backgroundColor: Colors.transparent, | |
| alignment: Alignment.topRight, | |
| padding: EdgeInsets.zero, | |
| label: Icon( | |
| Icons.highlight_off_outlined, | |
| color: Colors.red, | |
| ), | |
| child: CircleAvatar( | |
| radius: 40.0, | |
| backgroundImage: AssetImage('assets/images/biryani.jpg'), | |
| ), | |
| ), | |
| const SizedBox( | |
| height: 10, | |
| ), | |
| const Badge( | |
| backgroundColor: Colors.transparent, | |
| alignment: Alignment.bottomRight, | |
| offset: Offset(-15, -20), | |
| // padding: EdgeInsets.zero, | |
| label: Icon( | |
| Icons.upload, | |
| color: Colors.black26, | |
| size: 30.0, | |
| ), | |
| child: CircleAvatar( | |
| radius: 40.0, | |
| backgroundColor: Colors.blue, | |
| child: Center( | |
| child: Text( | |
| "M", | |
| style: TextStyle(fontSize: 30.0, color: Colors.white), | |
| ), | |
| ), | |
| ), | |
| ), | |
| const SizedBox( | |
| height: 30, | |
| ), | |
| Badge( | |
| backgroundColor: Colors.transparent, | |
| alignment: Alignment.bottomLeft, | |
| offset: const Offset(0, -5), | |
| label: const Icon( | |
| Icons.favorite, | |
| color: Colors.red, | |
| ), | |
| child: Container( | |
| padding: const EdgeInsets.all(16.0), | |
| decoration: BoxDecoration( | |
| color: Colors.blueAccent, | |
| borderRadius: BorderRadius.circular(18), | |
| ), | |
| child: const Text( | |
| "Some text message", | |
| style: TextStyle(color: Colors.white), | |
| ), | |
| ), | |
| ) | |
| ], | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment