Flutter Dev, did you know how to fix this icon? - flutter

When you use vscode and call Icon(Icons."the icon") to your code, the icon always showed up in the code line number section right (I don't about Android Studio). The scale icon that I called doesn't appear on the side, then when I hover my cursor, the scale image is broken. how do I fix it?
This is the code
import 'package:flutter/material.dart';
import 'package:project_ukk/constants/color_constant.dart';
import 'package:bubble_bottom_bar/bubble_bottom_bar.dart';
import 'package:project_ukk/pages/user_page/collection/collection_page.dart';
import 'package:project_ukk/pages/user_page/home/home_page.dart';
import 'package:project_ukk/pages/user_page/profile/profile_page.dart';
import 'package:project_ukk/pages/user_page/search/auction_page.dart';
class PageNavBar extends StatefulWidget {
const PageNavBar({Key? key}) : super(key: key);
#override
State<PageNavBar> createState() => _PageNavBarState();
}
class _PageNavBarState extends State<PageNavBar> {
int currentIndex = 0;
void changePage(int? index) {
setState(() {
currentIndex = index!;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
print('button pressed');
},
child: const Icon(
Icons.add,
size: 35,
),
backgroundColor: kRedColor,
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
body: <Widget>[
HomePage(0),
AuctionPage(1),
CollectionPage(2),
ProfilePage(3),
][currentIndex],
bottomNavigationBar: BubbleBottomBar(
hasNotch: true,
fabLocation: BubbleBottomBarFabLocation.end,
opacity: 0.2,
currentIndex: currentIndex,
onTap: changePage,
borderRadius: const BorderRadius.vertical(
top: Radius.circular(16),
),
elevation: 8,
tilesPadding: const EdgeInsets.symmetric(vertical: 8.0),
items: const <BubbleBottomBarItem>[
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.dashboard_outlined,
color: kBlackColor,
),
activeIcon: Icon(
Icons.dashboard_rounded,
color: kModerateCyan,
),
title: Text('Home'),
),
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.scale_outlined,
color: kBlackColor,
),
activeIcon: Icon(
Icons.scale,
color: kPowderBlue,
),
title: Text('Logs'),
),
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.collections_outlined,
color: kBlackColor,
),
activeIcon: Icon(
Icons.collections,
color: kLightRedColor,
),
title: Text('Logs'),
),
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.person_outline,
color: kBlackColor,
),
activeIcon: Icon(
Icons.person,
color: kLightOrange,
),
title: Text('Logs'),
)
],
),
);
}
}

This problem is not related to Flutter or Dart in any way - that's the IDE issue you are using (it seems that you are using Visual Studio Code).
In fact, this is a known issue that is mentioned in the Flutter context here and globally here.

Related

My bottom navigation bar is not changing it's index while using will pop scope on it's children

I want that whenever I press back button of Android while on a page of nav bar, it should change it's index to 0, i.e. I should land on the first page of it. But it is not happening. My code -
import 'dart:math';
import '../colors.dart';
import '../providers.dart';
import 'home_tab/home_tab_screen.dart';
import 'manage_leads/mange_leads_screen.dart';
import 'profile/profile_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';
import '../main.dart';
import '../size_config.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List<Widget> screens = [
HomeTabScreen(),
WillPopScope(
onWillPop: () async {
Provider.of<MyAppData>(navigatorKey.currentContext!, listen: false)
.initializePage(0);
return false;
},
child: ManageLeadsScreen(),
),
Container(),
WillPopScope(
onWillPop: () async {
Provider.of<MyAppData>(navigatorKey.currentContext!, listen: false)
.initializePage(0);
print(Provider.of<MyAppData>(navigatorKey.currentContext!, listen: false).pageIndex);
return false;
},
child: ProfileScreen(),
),
];
void _onItemTapped(int index) {
setState(() {
Provider.of<MyAppData>(navigatorKey.currentContext!, listen: false).initializePage(index);
});
}
#override
Widget build(BuildContext context) {
SizeConfig().init(context);
return Scaffold(
backgroundColor: Colors.white,
extendBody: true,
body: screens[Provider.of<MyAppData>(navigatorKey.currentContext!, listen: true).pageIndex],
bottomNavigationBar: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 1,
blurRadius: 20,
offset: Offset.fromDirection(-pi / 2, 10))
],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
),
child: BottomNavigationBar(
backgroundColor: Colors.white,
iconSize: getProportionateScreenWidth(32),
selectedFontSize: getProportionateScreenWidth(12),
selectedItemColor: primaryOrange,
unselectedIconTheme: IconThemeData(
size: getProportionateScreenWidth(24),
),
type: BottomNavigationBarType.fixed,
showUnselectedLabels: false,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(
Icons.home,
color: unselectedItemColor,
),
label: 'Home',
activeIcon: Icon(
Icons.home,
color: primaryOrange,
),
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
"assets/icons/manage_leads_icon.svg",
color: unselectedItemColor,
),
label: 'Manage Leads',
activeIcon: SvgPicture.asset(
"assets/icons/manage_leads_icon.svg",
color: primaryOrange,
),
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
"assets/icons/icon_3.svg",
color: unselectedItemColor,
),
label: 'Next',
activeIcon: SvgPicture.asset(
"assets/icons/icon_3.svg",
color: Colors.orange,
),
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
"assets/icons/profile_icon.svg",
color: unselectedItemColor,
),
label: 'Home',
activeIcon: SvgPicture.asset(
"assets/icons/profile_icon.svg",
color: Colors.orange,
),
),
],
currentIndex: Provider.of<MyAppData>(navigatorKey.currentContext!, listen: true).pageIndex,
onTap: _onItemTapped,
),
),
),
);
}
}
Here is my initializePage function -
import 'package:flutter/cupertino.dart';
class MyAppData extends ChangeNotifier {
int pageIndex=0;
void initializePage(int num) {
pageIndex = num;
notifyListeners();
}
}
When I am changing it's value using onTap: _onItemTapped,, it is working fine, but when I am trying to change it using WillPopScope, it's not working. Using print statements, I can see that value of pageIndex is changing to 0, but my nav bar is not reponsive. Only after I hot reload, it goes back to the first screen.
I think this example may help you.
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: ChangeNotifierProvider(
create: (_) => MyAppData(), child: HomeScreen()),
);
}
}
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List<Widget> screens(BuildContext context) => [
WillPopScope(
onWillPop: () async {
_onItemTapped(0);
return false;
},
child: Container(
color: Colors.primaries[0],
child: Center(
child: Text("Page 0"),
),
),
),
WillPopScope(
onWillPop: () async {
_onItemTapped(0);
return false;
},
child: Container(
color: Colors.primaries[1],
child: Center(
child: Text("Page 1"),
),
),
),
WillPopScope(
onWillPop: () async {
_onItemTapped(0);
return false;
},
child: Container(
color: Colors.primaries[2],
child: Center(
child: Text("Page 2"),
),
),
),
WillPopScope(
onWillPop: () async {
_onItemTapped(0);
return false;
},
child: Container(
color: Colors.primaries[3],
child: Center(
child: Text("Page 3"),
),
),
),
];
void _onItemTapped(int index) {
context.read<MyAppData>().initializePage(index);
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
extendBody: true,
body: screens(context)[context.watch<MyAppData>().pageIndex],
bottomNavigationBar: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
),
child: BottomNavigationBar(
backgroundColor: Colors.white,
iconSize: 30,
selectedFontSize: 20,
selectedItemColor: Colors.red,
unselectedIconTheme: IconThemeData(
size: 20,
),
type: BottomNavigationBarType.fixed,
showUnselectedLabels: false,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(
Icons.home,
),
label: 'page0',
activeIcon: Icon(
Icons.home,
),
),
BottomNavigationBarItem(
icon: Icon(
Icons.home,
),
label: 'page1',
activeIcon: Icon(
Icons.home,
),
),
BottomNavigationBarItem(
icon: Icon(
Icons.home,
),
label: 'page2',
activeIcon: Icon(
Icons.home,
),
),
BottomNavigationBarItem(
icon: Icon(
Icons.home,
),
label: 'page3',
activeIcon: Icon(
Icons.home,
),
),
],
currentIndex: context.watch<MyAppData>().pageIndex,
onTap: _onItemTapped,
),
),
),
);
}
}
class MyAppData extends ChangeNotifier {
int pageIndex = 0;
void initializePage(int num) {
pageIndex = num;
notifyListeners();
}
}

Flutter - Call onTap from another widget

I have a convex bottom bar and the last tab is a Menu that opens a drawer when clicked. But I'm having troubles when the drawer is closed. As the tab Menu only opens a drawer I wish it could return to previous tab when drawer closes, but the Menu tab keeps active. The tab only changes when it is clicked. So how can I call the onTab property of convex_tab_bar when the drawer is closed?
...
return Scaffold(
key: _scaffoldKey,
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text('Drawer Header'),
),
ListTile(
title: const Text('Item 1'),
onTap: () {},
),
],
),
),
onDrawerChanged: (isOpen) {
if (!isOpen) {
setState(() {
_currentOption = _previousOption;
});
changeTab(context, _previousOption);
}
},
body: Container(
child: _currentPage,
),
bottomNavigationBar: StyleProvider(
style: Style(),
child: ConvexAppBar(
style: TabStyle.fixedCircle,
backgroundColor: Colors.white,
color: Colors.grey,
activeColor: _currentOption == 1
? const Color(0xffa98e47)
: const Color(0xff00c9ff),
items: [
TabItem(
icon: const Icon(
ReceivedIcon.receivedIcon,
color: Colors.grey,
size: 12,
),
title: AppLocalizations.of(context)!.received,
activeIcon: const Icon(
ReceivedIcon.receivedIcon,
color: Color(0xff00c9ff),
size: 12,
),
),
TabItem(
icon: const Icon(SentIcon.sentIcon, color: Colors.grey),
title: AppLocalizations.of(context)!.sent,
activeIcon: const Icon(SentIcon.sentIcon, color: Color(0xffa98e47)),
),
const TabItem(
icon: Icon(
Icons.add_rounded,
size: 48,
color: Colors.white,
)
),
TabItem(
icon: Icons.notifications,
title: AppLocalizations.of(context)!.notifications
),
TabItem(
icon: Icons.menu,
title: AppLocalizations.of(context)!.menu
),
],
onTap: (int i) {
changeTab(context, i);
},
),
),
);
try this https://github.com/hacktons/convex_bottom_bar/blob/master/doc/issue-change-active-tab-index.md (Change active tab index programmaticlly)
create a function onTapHandler in your class ... put the referece on your ConvexAppBar(onTap:onTapHandler ...) and now you are able to call the onTapHandler in your onDrawerChanged handler

remove space between bottom nav bar and bottom of screen

I created my own bottom app bar following a tutorial. However, there is a white space between the bottom nav bar and the bottom of the screen. I colored this space in white to show it. How can I make my container the actual nav bar and hide that space?
This is happening on all of my screens in the app regardless if they begin with a scaffold, column, container etc.
import 'package:flutter/material.dart';
class bottomAppBar extends StatelessWidget {
const bottomAppBar({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return BottomAppBar(
color: Colors.white,
child: Container(
color: Color(0xFF313131).withOpacity(0.7),
height: 50,
width: double.maxFinite,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/');
},
icon: Icon(
Icons.home,
color: Colors.white,
),
),
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/discover');
},
icon: Icon(
Icons.search,
color: Colors.white,
),
),
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/mybookings');
},
icon: Icon(
Icons.hello,
color: Colors.white,
),
),
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/user');
},
icon: Icon(
Icons.person,
color: Colors.white,
),
),
],
),
),
);
}
}
This happens because you use the scaffold propery from the materail app. But, never wrap the widget with the scaffold widget.
After wraping the widget in scaffold use the bottomNavigationBar property to put your BottomAppBar. Then every thing will work perfect.
Thank you.
Code (Your updated code)
import 'package:flutter/material.dart';
class bottomAppBar extends StatelessWidget {
const bottomAppBar({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomAppBar(
color: Colors.white,
child: Container(
color: Color(0xFF313131).withOpacity(0.7),
height: 50,
width: double.maxFinite,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/');
},
icon: Icon(
Icons.home,
color: Colors.white,
),
),
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/discover');
},
icon: Icon(
Icons.search,
color: Colors.white,
),
),
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/mybookings');
},
icon: Icon(
Icons.ac_unit,
color: Colors.white,
),
),
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/user');
},
icon: Icon(
Icons.person,
color: Colors.white,
),
),
],
),
),
),
);
}
}
Output Screen

App bar is too big and the icons don't fit

I am trying to resize the app bar but no change to make the width perfect for the icons to fit.
This is the code that I am using for it
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tariffo/Detail.dart';
import 'package:tariffo/favoriteProviders.dart';
import 'package:tariffo/messages_list.dart';
import 'package:bubble_bottom_bar/bubble_bottom_bar.dart';
import 'HomePage.dart';
class BarDetail extends StatefulWidget {
#override
_BarDetailState createState() => _BarDetailState();
}
class _BarDetailState extends State<BarDetail> {
int currentIndex;
#override
void initState() {
super.initState();
currentIndex = 0;
}
changePage(int index) {
setState(() {
currentIndex = index;
});
}
#override
Widget build(BuildContext context) {
return Transform.translate(
offset: Offset(0.0, -50),
child: Container(
height: 82,
margin: EdgeInsets.only(left: 20, right: 20),
child: ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(40),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
BubbleBottomBar(
opacity: 0.2,
backgroundColor: Colors.white10,
borderRadius:
BorderRadius.vertical(top: Radius.circular(80.0)),
currentIndex: currentIndex,
hasInk: true,
inkColor: Colors.black12,
hasNotch: true,
onTap: (index) {
if (index == 1)
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FavoriteProviders()),
);
if (index == 2)
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Searchbar()),
);
if (index == 3)
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MessageList()),
);
},
elevation: 100,
items: <BubbleBottomBarItem>[
BubbleBottomBarItem(
backgroundColor: Colors.blue,
icon: Icon(
Icons.dashboard,
color: Colors.black,
size: 20,
),
activeIcon: Icon(Icons.dashboard,
color: Colors.blue, size: 20),
title: Text(
"Home",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 15),
),
),
BubbleBottomBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.favorite_border,
color: Colors.black, size: 20),
activeIcon: Icon(Icons.dashboard,
color: Colors.red, size: 20),
title: Text("Saved")),
BubbleBottomBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.whatshot,
color: Colors.black, size: 20),
activeIcon: Icon(Icons.dashboard,
color: Colors.red, size: 20),
title: Text("Search")),
BubbleBottomBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.send,
color: Colors.black, size: 20),
activeIcon: Icon(Icons.dashboard,
color: Colors.red, size: 20),
title: Text("Messages")),
]),
],
))));
}
}
Any idea what I should change? the height of the container ? the border radius? It's about the elevation? This app bar is only on my homepage.
[1]: https://i.stack.imgur.com/ZDjNv.png
I would say to remove the Column, the height of the container, and change the margin to all :
margin: EdgeInsets.all(20),
If you need to align some stuff :
How to align single widgets in Flutter?
EDIT :
Using the example from the package (bubble_bottom_bar) works pretty well :
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
backgroundColor: Colors.red,
bottomNavigationBar: BarDetail(),
),
);
}
}
class BarDetail extends StatefulWidget {
#override
_BarDetailState createState() => _BarDetailState();
}
class _BarDetailState extends State<BarDetail> {
int currentIndex;
#override
void initState() {
super.initState();
currentIndex = 0;
}
changePage(int index) {
setState(() {
currentIndex = index;
});
}
#override
Widget build(BuildContext context) {
return BubbleBottomBar(
// backgroundColor: Colors.red,
opacity: 0.2,
currentIndex: currentIndex,
onTap: changePage,
borderRadius: BorderRadius.vertical(top: Radius.circular(50)),
elevation: 8,
hasNotch: true,
hasInk: true,
inkColor: Colors.black12,
items: <BubbleBottomBarItem>[
BubbleBottomBarItem(
backgroundColor: Colors.red,
icon: Icon(
Icons.dashboard,
color: Colors.black,
),
activeIcon: Icon(
Icons.dashboard,
color: Colors.red,
),
title: Text("Home")),
BubbleBottomBarItem(
backgroundColor: Colors.deepPurple,
icon: Icon(
Icons.access_time,
color: Colors.black,
),
activeIcon: Icon(
Icons.access_time,
color: Colors.deepPurple,
),
title: Text("Logs")),
BubbleBottomBarItem(
backgroundColor: Colors.indigo,
icon: Icon(
Icons.folder_open,
color: Colors.black,
),
activeIcon: Icon(
Icons.folder_open,
color: Colors.indigo,
),
title: Text("Folders")),
BubbleBottomBarItem(
backgroundColor: Colors.green,
icon: Icon(
Icons.menu,
color: Colors.black,
),
activeIcon: Icon(
Icons.menu,
color: Colors.green,
),
title: Text("Menu"))
],
);
}
}

Adding onPressed or onTab to BubbleBottomBarItem in Flutter

Been trying to solve this all day.
I am basically new to flutter.
I want the Bottom icon buttons to have its own onTap methods like the normal FAB or BottomNavigationBar. please help! Thank you
Here is the code.
return BubbleBottomBar(
hasNotch: true,
opacity: .2,
currentIndex: currentIndex,
onTap: changePage,
borderRadius: BorderRadius.vertical(
top: Radius.circular(
16)),
elevation: 8,
items: <BubbleBottomBarItem>[
BubbleBottomBarItem(
backgroundColor: Colors.indigo,
icon: Icon(
Icons.home,
color: Colors.black,
),
activeIcon: Icon(
Icons.home,
color: Colors.indigo,
),
title: Text("Home")),
BubbleBottomBarItem(
backgroundColor: Colors.indigo,
icon: Icon(
Icons.folder_open,
color: Colors.black,
),
activeIcon: Icon(
Icons.folder_open,
color: Colors.indigo,
),
title: Text("Get Job")),
BubbleBottomBarItem(
backgroundColor: Colors.indigo,
icon: Icon(
Icons.add_circle_outline,
color: Colors.black,
),
activeIcon: Icon(
Icons.add_circle_outline,
color: Colors.indigo,
),
title: Text("Add Job")),
],
);
}
}
The BubbleBottomBarItem does not have any onTap or onPressed method, hence you need to use onTap in BubbleBottomBar. You can implement changePage as given in below example to handle the onTap in BubbleBottomBar.
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int currentIndex;
#override
void initState() {
// TODO: implement initState
super.initState();
currentIndex = 0;
}
void changePage(int index) {
setState(() {
currentIndex = index;
});
//You can have a switch case to Navigate to different pages
switch (currentIndex){
case 0:
Navigator.push( context,
MaterialPageRoute(builder: (context) => AnyClass()),
);
break;
...
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
bottomNavigationBar: BubbleBottomBar(
hasNotch: true,
fabLocation: BubbleBottomBarFabLocation.end,
opacity: .2,
currentIndex: currentIndex,
onTap: changePage,
borderRadius: BorderRadius.vertical(
top: Radius.circular(
16)),
elevation: 8,
items: <BubbleBottomBarItem>[
...
],
),
);
}
}