on appbar, i want to return to previous page using icon. but it keep saying that the argument type 'context' cant be assigned to the parameter type 'BuildContext'.
AppBar app_bar_parking ({String title = ''}) {
return AppBar(
backgroundColor: Colors.white,
centerTitle: true,
title: Text('Parking & Pay'),
elevation: 0,
titleTextStyle: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20),
leading: GestureDetector(
child: IconButton(
icon: Icon(Icons.arrow_back_ios_new_outlined,
size: 20,
color: Colors.lightBlue,),
onPressed: () {
Navigator.pop(context);
}
),
)
);
}
Because into your class you do not have a context declaration.
Add BuildContext context to the parameters you need.
AppBar app_bar_parking(BuildContext context, {String title = ''}) {
return AppBar(
backgroundColor: Colors.white,
centerTitle: true,
title: Text('Parking & Pay'),
elevation: 0,
titleTextStyle:
TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20),
leading: GestureDetector(
child: IconButton(
icon: Icon(
Icons.arrow_back_ios_new_outlined,
size: 20,
color: Colors.lightBlue,
),
onPressed: () {
Navigator.pop(context);
}),
));
}
and when you use your app_bar_parking remember to add the context as:
app_bar_parking(context, "MyTitle");
Pass the context in the function.
AppBar app_bar_parking ({String title = '',BuildContext context}) {
return AppBar(
backgroundColor: Colors.white,
centerTitle: true,
title: Text('Parking & Pay'),
elevation: 0,
titleTextStyle: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20),
leading: GestureDetector(
child: IconButton(
icon: Icon(Icons.arrow_back_ios_new_outlined,
size: 20,
color: Colors.lightBlue,),
onPressed: () {
Navigator.pop(context);
}
),
)
);
}
Now use inside the build()
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: app_bar_parking('',context),
// rest of the code
);
}
Add BuildContext context in your function parameter. Basically, you have to use the same context.
app_bar_parking ({String title = '',BuildContext context}) {}
Related
I've tried to change the child from column to other types but still it didn't work. I'm not sure what's causing the error here but I'm suspecting its the screens[_currentindex] placement. Also when i click on one of the items in the bottom bar. The background color (dark blue) doesn't change to the color of my desired page. but current content disappears.
class _MyStatefulWidgetState extends State<focalPointProfile> {
**int _currentIndex = 0;**
Widget build(BuildContext context) {
**final List<Widget> screens = [
dashboardScreen(),
focalPointProfile(),
mentorRegistrationScreen(), ];**
return Scaffold(
resizeToAvoidBottomInset: false,
endDrawer: drawer(),
appBar: AppBar(
actions: [
Builder(
builder: (context) => IconButton(
icon: Icon((Icons.settings), color: Colors.green,),
onPressed: () => Scaffold.of(context).openEndDrawer(),
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
),
),
],
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
elevation: 1,
),
backgroundColor: Colors.blueGrey[800],
body: SafeArea(
minimum: const EdgeInsets.only(top: 100),
child: Column(
children: <Widget>[
Text(
name,
style: TextStyle(
fontSize: 40.0,
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: "Source Sans Pro",
),
),
Text(
position,
style: TextStyle(
fontSize: 30,
color: Colors.blueGrey[200],
letterSpacing: 2.5,
fontWeight: FontWeight.bold,
fontFamily: "Source Sans Pro"),
),
SizedBox(
height: 20,
width: 200,
child: Divider(
color: Colors.white,
),
),
// we will be creating a new widget name info carrd
buildTextField(email, Icons.web),
**screens[_currentIndex],**
],
),
),
**bottomNavigationBar: NavigationBar(
height: 50,
selectedIndex: _currentIndex,
onDestinationSelected: (index) => setState(() => _currentIndex = index),
destinations: const [
NavigationDestination(icon: Icon(Icons.home), label: 'home'),
NavigationDestination(icon: Icon(Icons.person), label: 'profile'),
NavigationDestination(icon: Icon(Icons.add), label: 'Add Mentor'),
],
),**
);
}
class _MyStatefulWidgetState extends State<focalPointProfile>
cant be the same as here
**final List<Widget> screens = [
dashboardScreen(),
focalPointProfile(),
mentorRegistrationScreen(), ];
You can read it here.
https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html
My problem
I want make search icons button
text field appears at the bottom of the button when button is clicked
Are there any documents or sites I can refer to?
My code -- makes StatefulWidget --
appBar: AppBar(
backgroundColor: const Color(0xffffffff),
centerTitle: true,
title: Text(
'CREW',
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w900),
),
elevation: 0.0,
actions: [
IconButton(icon: Icon(Icons.search), onPressed: (){
}),
IconButton(icon: Icon(Icons.notifications), onPressed: null),
],
**Try below code to add search bar in appbar.**
AppBar(
backgroundColor: const Color(0xffffffff),
centerTitle: true,
title: Text(
'CREW',
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w900),
),
elevation: 0.0,
actions: [
// Navigate to the Search Screen
IconButton(
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => const SearchPage())),
icon: const Icon(Icons.search)),
IconButton(icon: Icon(Icons.notifications), onPressed: null),
],
),
//search ui & page
class SearchPage extends StatelessWidget {
const SearchPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// The search area here
title: Container(
width: double.infinity,
height: 40,
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(5)),
child: Center(
child: TextField(
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search),
suffixIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
/* Clear the search field */
},
),
hintText: 'Search...',
border: InputBorder.none),
),
),
)),
);
}
I have a flutter app that displays a list of users from a RESTapi in a list view. However I would like to show the list of users in an expansion tile so as to show more details about them. Here is the method for fetching the data:
final String apiURL = 'https://jsonplaceholder.typicode.com/users';
Future<List<Users>> fetchJSONData() async {
var jsonResponse = await http.get(Uri.parse(apiURL));
if (jsonResponse.statusCode == 200) {
final jsonItems =
json.decode(jsonResponse.body).cast<Map<String, dynamic>>();
List<Users> usersList = jsonItems.map<Users>((json) {
return Users.fromJson(json);
}).toList();
return usersList;
} else {
throw Exception('Failed to load data from internet');
}
}
This is the code used to display the list of users:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sample Customer List'),
backgroundColor: Theme.of(context).accentColor,
),
body: _buildExpanded());
}
Widget _showListTile() {
return FutureBuilder<List<Users>>(
future: fetchJSONData(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
return ListView(
children: snapshot.data
.map(
(user) => Slidable(
actionPane: SlidableScrollActionPane(),
actions: <Widget>[
IconSlideAction(
caption: 'Archive',
color: Colors.blue,
icon: Icons.archive,
onTap: () => print('Archiving'),
),
IconSlideAction(
caption: 'Share',
color: Colors.green,
icon: Icons.share,
onTap: () => print('Share'),
)
],
actionExtentRatio: 1 / 5,
child: ListTile(
title: Text(user.name),
onTap: () {
print(user.name);
},
subtitle: Text(user.phoneNumber),
leading: CircleAvatar(
backgroundColor: Colors.green,
child: Text(user.name[0],
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
)),
),
),
secondaryActions: <Widget>[
IconSlideAction(
caption: 'More',
color: Colors.black45,
icon: Icons.more_horiz,
onTap: () => print('More'),
),
IconSlideAction(
caption: 'Delete',
color: Colors.red,
icon: Icons.delete,
onTap: () => print('Delete'),
),
],
),
)
.toList(),
);
},
);
}
What do I need to do to implement an expansion tile is this app?
For Example
ExpansionTile(
title: Text(user.name),
subtitle: Text(user.phoneNumber),
leading: CircleAvatar(
backgroundColor: Colors.green,
child: Text(user.name[0],
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
)),
),
children: [
Text(
"${user.email}",
style: TextStyle(fontSize: 18),
),
Text(
"${user.address}",
style: TextStyle(fontSize: 18),
),
// ...
// other information you want to show
])
OR you can push other page to show detail.
I want to have the title in my SliverAppBar fade in the default way however it stops working once I apply style to the text. You can see how it behave with and without TextStyle. Nothing else changes.
No style
Style applied
Here's the code with style applied:
class FeedScreen extends StatelessWidget {
static const routeName = "/feed_screen";
#override
Widget build(BuildContext context) {
return ViewModelBuilder<WhosHereScreenViewModel>.reactive(
disposeViewModel: false,
initialiseSpecialViewModelsOnce: true,
viewModelBuilder: () => locator<WhosHereScreenViewModel>(),
builder: (context, model, child) {
return Scaffold(
backgroundColor: Colors.white,
body: model.isBusy == true
? Center(child: CircularProgressIndicator())
: CustomScrollView(slivers: [
SliverAppBar(
brightness: Brightness.light,
backgroundColor: Colors.white,
title: Text(
'miit',
style: TextStyle(
fontFamily: 'Changa',
fontWeight: FontWeight.w600,
fontSize: 36.0,
color: Colors.black87),
),
titleSpacing: -4.0,
leading: IconButton(
icon: Image.asset('assets/images/new_logo.png'),
onPressed: () {},
),
floating: true,
actions: [
Padding(
padding: const EdgeInsets.only(right: 12.0),
//TODO build filter functionality
child: IconButton(
icon: Icon(Mdi.accountDetailsOutline,
color: Colors.black87, size: 30.0),
onPressed: null),
)
],
),
Just pass text style not in Text widget in title, but in titleTextStyle.
title: Text('miit'),
titleTextStyle: TextStyle(
fontFamily: 'Changa',
fontWeight: FontWeight.w600,
fontSize: 36.0,
color: Colors.black87),
I'm having a problem right now in my bottom navigation in flutter.
I have four navigation "Community, Feeds, Activity, Profile".
In my "Feeds" navigation I have a button named "View Profile" everytime I click that button it directs me to a new screen using
"Navigator.push(context, MaterialPageRoute())"
and I notice it auto generates a "<-" or "back arrow" icon on the appbar.
The problem is everytime I click that "back arrow", it redirects me to the first option on my navigation bar.
Not on the "Feeds" navigation.
Any tips how to fix this?
Here is my bottom navigation code:
_getPage(int page) {
switch (page) {
case 0:
return NewsFeed();
case 1:
return OrgAndNews();
case 2:
return MyActivity();
case 3:
return Profile();
}
}
int currentPage = 0;
void _onBottomNavBarTab(int index) {
setState(() {
currentPage = index;
});
}
return Scaffold(
body: Container(
child: _getPage(currentPage),
),
bottomNavigationBar: Container(
height: _height * .09,
child: BottomNavigationBar(
backgroundColor: Color(0xFFFFFFFF),
fixedColor: Color(0xFF121A21),
unselectedItemColor: Color(0xFF121A21),
currentIndex: currentPage,
onTap: _onBottomNavBarTab,
items: [
BottomNavigationBarItem(
icon: Icon(FontAwesomeIcons.users),
title: Padding(
padding: const EdgeInsets.only(top: 3.0),
child: Text('Community', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(35),
fontWeight: FontWeight.w800),
),
),
),
BottomNavigationBarItem(
icon: Icon(FontAwesomeIcons.newspaper),
title: Padding(
padding: const EdgeInsets.only(top: 3.0),
child: Center(
child: Text('Feeds', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(35),
fontWeight: FontWeight.w800),),
),
),
),
BottomNavigationBarItem(
icon: Icon(FontAwesomeIcons.listUl),
title: Padding(
padding: const EdgeInsets.only(top: 3.0),
child: Text('My Activity', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(35),
fontWeight: FontWeight.w800),),
),
),
BottomNavigationBarItem(
icon: Icon(FontAwesomeIcons.userAlt),
title: Padding(
padding: const EdgeInsets.only(top: 3.0),
child: Text('Profile', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(35),
fontWeight: FontWeight.w800),),
),
),
],
),
),
);
My code for the page when you click the "View Profile":
class OrgProfile extends StatefulWidget {
OrgProfile(this.orgName) : super();
final String orgName;
#override
_OrgProfileState createState() => _OrgProfileState();
}
class _OrgProfileState extends State<OrgProfile> {
#override
final db = Firestore.instance;
Container buildItem(DocumentSnapshot doc) {
return Container(
child: Column(
children: <Widget>[
Center(
child: Padding(
padding: const EdgeInsets.only(top: 20.0),
child: CircleAvatar(
radius: 70,
),
),
),
Text(
'${doc.data['Email']}',
style: TextStyle(color: Colors.black),
)
],
),
);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.orgName),
),
body: StreamBuilder<QuerySnapshot>(
stream: db
.collection('USERS')
.where('Name of Organization', isEqualTo: widget.orgName)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: snapshot.data.documents
.map((doc) => buildItem(doc))
.toList());
} else {
return SizedBox();
}
}),
);
}
}
My code when i click the "View Profile" button:
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => new
OrgProfile(
doc.data['Name of Organization'])));
},
My feeds UI:
My View Profile UI:
Have you used MaterialPage Route With Builder Like This?
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => new MyToDoThunder(),
),
)
Homepage Code :-
class HomePage extends StatefulWidget {
#override
State<StatefulWidget> createState() {
//
return new HomePageState();
}
}
class HomePageState extends State<HomePage> {
var db = DatabaseHelper();
int _selectedIndex = 0;
List<bool> textColorChange = [true, false, false, false];
final _widgetOptions = [
StatusPageRedux(),
RequestPage(),
NotificationPage(),
DashboardPage(),
];
_bottomNavigationView() {
return new Theme(
isMaterialAppTheme: true,
data: Theme.of(context)
.copyWith(canvasColor: Theme.of(context).primaryColor),
child: new BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: _onItemTapped,
currentIndex: _selectedIndex,
fixedColor: Colors.white,
items: [
new BottomNavigationBarItem(
activeIcon: ThunderSvgIcons(
path: 'assets/icons/Status.svg', height: 20.0, color: Colors.white),
icon: ThunderSvgIcons(
path: 'assets/icons/Status.svg', height: 20.0, color: Colors.white30),
title: new Text(
'Status',
style: TextStyle(
color: textColorChange[0] ? Colors.white : Colors.white30),
),
),
new BottomNavigationBarItem(
title: new Text(
'Requests',
style: TextStyle(
color: textColorChange[1] ? Colors.white : Colors.white30),
),
activeIcon: ThunderSvgIcons(
path: 'assets/icons/Requests.svg', height: 20.0, color: Colors.white),
icon: ThunderSvgIcons(
path: 'assets/icons/Requests.svg',
height: 20.0,
color: Colors.white30),
),
new BottomNavigationBarItem(
activeIcon: ThunderSvgIcons(
path: 'assets/icons/Notifications.svg',
height: 20.0,
color: Colors.white),
icon: ThunderSvgIcons(
path: 'assets/icons/Notifications.svg',
height: 20.0,
color: Colors.white30),
title: new Text(
'Notifications',
style: TextStyle(
color: textColorChange[2] ? Colors.white : Colors.white30),
),
),
new BottomNavigationBarItem(
activeIcon: ThunderSvgIcons(
path: 'assets/icons/dashboard.svg',
height: 20.0,
color: Colors.white),
icon: ThunderSvgIcons(
path: 'assets/icons/dashboard.svg',
height: 20.0,
color: Colors.white30),
title: new Text(
'Dashboard',
style: TextStyle(
color: textColorChange[3] ? Colors.white : Colors.white30),
),
),
],
),
);
}
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(child: _widgetOptions.elementAt(_selectedIndex)),
bottomNavigationBar: _bottomNavigationView(),
);
}
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
for (int i = 0; i < textColorChange.length; i++) {
if (index == i) {
textColorChange[i] = true;
} else {
textColorChange[i] = false;
}
}
});
}
}
You will have to add your way back to the stack.
Try the below appbar in you 'tuloung duloung' title page, it should do the trick.
Note if your homescreen has tabs its advised to pass the index of the page you want to reach on exiting 'tuloung duloung'.
Let me know if it helps.
AppBar(
backgroundColor: Colors.transparent,
centerTitle: false,
brightness: Brightness.dark,
title: Container(
width: 150,
child: Row(
children:[
IconButton(icon:Icons.back_arrow,
onpressed:() =>
Navigator.pushReplacementNamed(context, '/Your Home_Screen');
),
Text('tuloung duloung',
style: TextStyle(
fontWeight: FontWeight.w400,
color: theme.primaryColor,
)),
]
),
),
automaticallyImplyLeading: false,
iconTheme: IconThemeData(
color: theme.primaryColor,
),
actions:[ Container(
width: 150,
child: FlatButton.icon(
label: Text('Done'),
icon: Icon(Icons.check_circle),
onPressed: () => {
setState(() {
takingsnap = true;
_captureImage();
})
}),
),
]
),