How to add text after the AppBar in Flutter - flutter

How do I go about this
I want to add something like a greeting, say "Hi James" before the Sliders , something like this
https://i.postimg.cc/cJQb8Cyz/Screenshot-1664302329.png
I wanted the greeting to be there , not sure how to go about it.
My source code is looking thus
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class TransactionDetails {
String? avatar;
String? name;
String? date;
String? amount;
TransactionDetails({
this.avatar,
this.name,
this.date,
this.amount,
});
TransactionDetails.fromJson(Map<String, dynamic> json) {
avatar = json['avatar'];
name = json['name'];
date = json['date'];
amount = json['amount'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['avatar'] = avatar;
data['name'] = name;
data['date'] = date;
data['amount'] = amount;
return data;
}
}
Future<List<TransactionDetails>> fetchAlbum() async {
final response = await http.get(Uri.parse(
'https://brotherlike-navies.000webhostapp.com/people/people.php'));
if (response.statusCode == 200) {
final List result = json.decode(response.body);
return result.map((e) => TransactionDetails.fromJson(e)).toList();
} else {
throw Exception('Failed to load data');
}
}
class BaseScreen extends StatelessWidget {
const BaseScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
"My Bank",
style: TextStyle(
fontFamily: "Poppins",
color: Colors.white,
fontWeight: FontWeight.bold),
),
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
backgroundImage:
NetworkImage('https://placeimg.com/640/480/people'),
),
),
actions: [
IconButton(
icon: Icon(Icons.notifications_active_outlined,
color: Colors.white, size: 27),
onPressed: () {})
],
),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: double.infinity,
height: 150,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
Container(
margin: const EdgeInsets.all(15),
width: 319,
height: 100,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(16)),
alignment: Alignment.center,
child: const Text(
'\$5200.00',
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
Container(
margin: const EdgeInsets.all(15),
width: 319,
height: 100,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(16)),
alignment: Alignment.center,
child: const Text(
'\$1200.00',
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
SizedBox(height: 24),
],
),
),
Padding(
padding: EdgeInsets.all(15),
child: Text(
"Recent Transactions",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.green),
),
),
Center(
child: FutureBuilder<List<TransactionDetails>>(
future: fetchAlbum(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(
child: Image.network(
snapshot.data![index].avatar.toString()),
),
title:
Text(snapshot.data![index].name.toString()),
trailing: Text(
snapshot.data![index].amount.toString()),
subtitle:
Text(snapshot.data![index].date.toString()),
);
});
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
return const CircularProgressIndicator();
}))
],
)));
}
}
How do i put the greeting before the Sliders? Help is needed.

Add Text widget for text and SizedBox for space. You can also use Padding widget around Text.
),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 20,
), //gap or use Padding widget
Text("Greatins"),
SizedBox(
height: 20,
), //gap
SizedBox(
height: 150,
with Padding widget
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(
top: 8,
bottom: 8,
),
child: Text("Greatins"),
),
SizedBox(
class BaseScreen extends StatelessWidget {
const BaseScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Padding(
padding: EdgeInsets.only(top: 1, left: 1),
child: Text(
"My Bank",
style: TextStyle(
fontFamily: "Poppins",
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
backgroundImage:
NetworkImage('https://placeimg.com/640/480/people'),
),
),
actions: [
IconButton(
icon: Icon(Icons.notifications_active_outlined,
color: Colors.white, size: 27),
onPressed: () {})
],
),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(
top: 8,
bottom: 8,
),
child: Text("Greatins"),
),
SizedBox(
height: 150,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
Container(
margin: const EdgeInsets.all(15),
width: 319,
height: 100,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(16)),
alignment: Alignment.center,
child: const Text(
'\$5200.00',
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
Container(
margin: const EdgeInsets.all(15),
width: 319,
height: 100,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(16)),
alignment: Alignment.center,
child: const Text(
'\$1200.00',
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
SizedBox(height: 24),
],
),
),
Padding(
padding: EdgeInsets.all(15),
child: Text(
"Recent Transactions",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.green),
),
),
Center(
child: FutureBuilder<List<TransactionDetails>>(
future: fetchAlbum(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(
child: Image.network(
snapshot.data![index].avatar.toString()),
),
title:
Text(snapshot.data![index].name.toString()),
trailing: Text(
snapshot.data![index].amount.toString()),
subtitle:
Text(snapshot.data![index].date.toString()),
);
});
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
return const CircularProgressIndicator();
}))
],
)));
}
}

Related

Title fetched from JSON data won't display inside card in Flutter mobile app

I have trouble displaying data in a widget that is inside a card. Below is the code to display the content inside the card via a widget. the code below is the widget that should display the project description and title on the dashboard page shown in the second image.
enter image description here
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:saas/models/dummy_model.dart';
import 'package:saas/network_utils/api.dart';
import 'progress_indicator_widget.dart';
// ignore: must_be_immutable
class ProjectWidget extends StatelessWidget {
final List<Project> _projects = <Project>[];
ProjectWidget({
Key? key,
}) : super(key: key);
Future<List<Project>> _fetchProjects() async {
var res = await Network().getData('users/project');
var projects = <Project>[];
if (res.statusCode == 200) {
var body = json.decode(res.body);
var tdata = body['data'];
var projectsJson = tdata;
for (var projectJson in projectsJson) {
projects.add(Project.fromJson(projectJson));
}
}
return projects;
}
#override
Widget build(BuildContext context) {
_fetchProjects().then((value) {
_projects.addAll(value);
});
return Flexible(
child: Column(children: [
ListView.builder(
shrinkWrap: true,
itemCount: _projects.length,
itemBuilder: (context, index) {
return Card(
color: Colors.yellow,
child: Row(
children: [
Container(
padding: const EdgeInsets.only(left: 10),
child: const Icon(Icons.list_alt, size: 12)),
Container(
padding: const EdgeInsets.only(left: 15),
child: Text(_projects[index].title,
style: const TextStyle(
fontSize: 16, color: Colors.black))),
Container(
padding: const EdgeInsets.only(left: 15),
child: const ProgressIndicatorWidget()),
Container(
padding: const EdgeInsets.only(left: 30),
child: IconButton(
icon:
const Icon(Icons.arrow_right, color: Colors.black),
onPressed: () {},
)),
],
));
},
)
]));
}
}
The code for the dashboard page in which I have put the widget is below:
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:saas/models/user_model.dart';
import 'package:saas/widgets/activities_widget.dart';
import 'package:saas/widgets/project_widget.dart';
class Dashboard extends StatefulWidget {
const Dashboard({Key? key, User? user}) : super(key: key);
#override
_DashboardState createState() => _DashboardState();
}
class _DashboardState extends State<Dashboard> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Column(children: [
Container(
height: 40,
width: double.infinity,
color: Colors.transparent,
),
SizedBox(
width: 390,
child: Card(
color: const Color.fromRGBO(0, 161, 39, 1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
color: const Color.fromRGBO(0, 161, 39, 1),
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.only(bottom: 30, top: 10),
child: Row(children: [
Column(
children: [
Container(
padding: const EdgeInsets.only(left: (15)),
child: const Text('M & E System',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold)))
],
),
Expanded(
child: Container(
padding: const EdgeInsets.only(left: 180),
margin: const EdgeInsets.all(6),
child: IconButton(
icon: const Icon(Icons.settings,
color: Colors.white),
onPressed: () {},
)),
)
])),
)),
SizedBox(
width: 390,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Column(children: [
Container(
margin: const EdgeInsets.all(5),
padding: const EdgeInsets.only(left: 5),
child: TextButton(
child: const Text('My Projects',
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold)),
onPressed: () {},
),
),
SizedBox(height: 150, child: ProjectWidget()),
]))),
SizedBox(
width: 390,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Column(children: [
Container(
margin: const EdgeInsets.all(5),
padding: const EdgeInsets.only(left: 5),
child: TextButton(
child: const Text('Current Activities',
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold)),
onPressed: () {},
),
),
Container(
padding: const EdgeInsets.all(5),
height: 200,
child: ActivitiesWidget()),
]))),
])));
}
}
showAlertDialog(BuildContext context) {
Widget logoutButton = TextButton(
child: const Text('Log Out',
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
onPressed: () => {});
AlertDialog alert = AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: const BorderSide(color: Color.fromRGBO(0, 161, 39, 1))),
content: const Text('Logout successful!',
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
actions: [
logoutButton,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
The function to fetch the data works as it is displaying the data in a list.
[enter image description here][2]
body: ListView.builder(
itemCount: _projects.length,
itemBuilder: (context, index) {
return Card(
child: Padding(
padding: const EdgeInsets.only(
top: 32.0, bottom: 32.0, left: 16.0, right: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
RichText(
text: TextSpan(children: [
const TextSpan(
text: 'Project Name: ',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black)),
TextSpan(
text: _projects[index].title,
style: const TextStyle(color: Colors.black))
])),
RichText(
text: TextSpan(children: [
const TextSpan(
text: 'Project Location: ',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black)),
TextSpan(
text: _projects[index].location,
style: const TextStyle(color: Colors.black))
])),
RichText(
text: TextSpan(children: [
const TextSpan(
text: 'Project Description: ',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black)),
TextSpan(
text: _projects[index].description,
style: const TextStyle(color: Colors.black))
])),
RichText(
text: TextSpan(children: [
const TextSpan(
text: 'Project Completion Date: ',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black)),
TextSpan(
text: _projects[index].endDate,
style: const TextStyle(color: Colors.black))
])),
]),
));
Any ideas on why it does not display the content inside the widget? So far there is no syntax error.
Here is full code it's working properly
just copy and past it I have reversed named for running in my device ( project class to => setting screen and dash screen have project code)
import 'package:flutter/material.dart';
// ignore: must_be_immutable
class SettingScreen extends StatelessWidget {
final List _projects = [];
SettingScreen({
Key? key,
}) : super(key: key);
// Future<List> _fetchProjects() async {
// var res = await Network().getData('users/project');
//
// var projects = <Project>[];
//
// if (res.statusCode == 200) {
// var body = json.decode(res.body);
// var tdata = body['data'];
// var projectsJson = tdata;
//
// for (var projectJson in projectsJson) {
// projects.add(Project.fromJson(projectJson));
// }
// }
// return projects;
// }
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Column(children: [
Container(
height: 40,
width: double.infinity,
color: Colors.transparent,
),
SizedBox(
width: 390,
child: Card(
color: const Color.fromRGBO(0, 161, 39, 1),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Container(
color: const Color.fromRGBO(0, 161, 39, 1),
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.only(bottom: 30, top: 10),
child: Row(children: [
Column(
children: [
Container(
padding: const EdgeInsets.only(left: (15)),
child: const Text('M & E System',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold)))
],
),
Expanded(
child: Container(
padding: const EdgeInsets.only(left: 180),
margin: const EdgeInsets.all(6),
child: IconButton(
icon: const Icon(Icons.settings, color: Colors.white),
onPressed: () {},
)),
)
])),
)),
SizedBox(
width: 390,
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Column(children: [
Container(
margin: const EdgeInsets.all(5),
padding: const EdgeInsets.only(left: 5),
child: TextButton(
child: const Text('My Projects',
style: TextStyle(
color: Colors.black, fontSize: 14, fontWeight: FontWeight.bold)),
onPressed: () {},
),
),
SizedBox(height: 250, child: Dashboard()),
]))),
SizedBox(
width: 390,
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
elevation: 10,
child: Column(children: [
Container(
margin: const EdgeInsets.all(5),
padding: const EdgeInsets.only(left: 5),
child: TextButton(
child: const Text('Current Activities',
style: TextStyle(
color: Colors.black, fontSize: 14, fontWeight: FontWeight.bold)),
onPressed: () {},
),
),
Container(
padding: const EdgeInsets.all(5),
height: 200,
child: Text("Activity widet()")),
// child: ActivitiesWidget()),
]))),
])));
}
}
showAlertDialog(BuildContext context) {
Widget logoutButton = TextButton(
child:
const Text('Log Out', style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
onPressed: () => {});
AlertDialog alert = AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: const BorderSide(color: Color.fromRGBO(0, 161, 39, 1))),
content: const Text('Logout successful!',
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
actions: [
logoutButton,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
class Dashboard extends StatefulWidget {
const Dashboard({Key? key}) : super(key: key);
#override
_DashboardState createState() => _DashboardState();
}
class _DashboardState extends State<Dashboard> {
#override
Widget build(BuildContext context) {
// _fetchProjects().then((value) {
// _projects.addAll(value);
// });
return SingleChildScrollView(
child: Column(children: [
ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: 12,
itemBuilder: (context, index) {
return Card(
color: Colors.yellow,
child: Row(
children: [
Container(
padding: const EdgeInsets.only(left: 10),
child: const Icon(Icons.list_alt, size: 12)),
Container(
padding: const EdgeInsets.only(left: 15),
child: Text("_projects[index].title",
style: const TextStyle(fontSize: 16, color: Colors.black))),
Container(
padding: const EdgeInsets.only(left: 15),
child: Text("Loader"),
),
Container(
padding: const EdgeInsets.only(left: 30),
child: IconButton(
icon: const Icon(Icons.arrow_right, color: Colors.black),
onPressed: () {},
)),
],
));
},
)
]),
);
}
}
it's scrolling perfectly :
steps1 : removed flexible
2: wrap with single child scroll view
3: give physics: NeverScrollableScrollPhysics(), to listview builder
done.....!

data not rendered in the first time

currently i'm trying to implement getx to my app, so far so good, i got the data i wanted but i'm kinda having some trouble when i tried to display the data to the screen.
This is where data supposed to be rendered as a horizontal listview
Home Screen
But apparently the data will only appear if i click the promo section and click back to the home section on bottom navigation.
Home Screen 2
Here is my home_controller.dart
class HomeController extends GetxController {
RxList<Hotels> listHotel = <Hotels>[].obs;
RxList<Province> listProvince = <Province>[].obs;
Future getListHotel() async {
final listHotel = await ApiService.getHotel();
this.listHotel.value = listHotel;
}
Future getListProvince() async {
final listProvince = await ApiService.getProvince();
this.listProvince.value = listProvince;
}
#override
void onInit() {
super.onInit();
getListHotel();
getListProvince();
}
}
and this is my home_screen.dart
Widget build(BuildContext context) {
final homeController = Get.put(HomeController());
final authController = Get.put(AuthController());
final orientation = MediaQuery.of(context).orientation;
return Scaffold(
body: SingleChildScrollView(
child: Builder(builder: (context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SafeArea(
child: Padding(
padding: EdgeInsets.only(
left: 5.w, right: 5.w, top: 100.h <= 667 ? 5.h : 4.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Daftar Hotel",
style: TextStyle(
color: const Color(0xffF0B900),
fontSize: 10.sp,
fontWeight: FontWeight.bold),
),
SizedBox(
height: 31.h,
width: orientation == Orientation.landscape
? 100.h
: 100.w,
child: ListView.separated(
shrinkWrap: true,
separatorBuilder: (BuildContext context, int index) {
return SizedBox(
width: 1.h,
);
},
scrollDirection: Axis.horizontal,
itemCount: homeController.listHotel.length,
itemBuilder: (context, i) {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HotelDetailScreen(
id: homeController
.listHotel[i].id,
checkin: checkInController.text
.toString(),
checkout: checkOutController.text
.toString(),
)));
},
child: SizedBox(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 70.w,
height: 20.h,
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.network(
homeController.listHotel[i].cover,
fit: BoxFit.cover,
),
),
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
homeController.listHotel[i].name,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 10.sp),
),
SizedBox(
width: 70.w,
child: Text(
homeController.listHotel[i].address,
maxLines: 2,
style: TextStyle(
fontWeight: FontWeight.w300,
fontSize: 10.sp),
overflow: TextOverflow.clip,
),
)
],
),
),
],
)),
);
},
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
"Rekomendasi",
style: TextStyle(
color: const Color(0xffF0B900),
fontSize: 10.sp,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 25.h,
width: orientation == Orientation.landscape
? 100.h
: 100.w,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: homeController.listProvince.length,
itemBuilder: (context, i) {
String imageUrl = "http://$CURRENT_URL/image/" +
homeController.listProvince[i].cover;
return InkWell(
onTap: () async {
await launch("https://turu.id/property");
},
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: SizedBox(
width: 30.w,
child: Stack(
children: [
SizedBox(
width: 30.w,
height: 25.h,
child: ClipRRect(
borderRadius:
BorderRadius.circular(12),
child: Image.network(
imageUrl,
fit: BoxFit.cover,
),
),
),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(12),
color:
Colors.black.withOpacity(0.2),
),
),
Padding(
padding: EdgeInsets.only(
left: 2.h, bottom: 2.h),
child: Column(
mainAxisAlignment:
MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
homeController
.listProvince[i].name,
style: TextStyle(
color: Colors.white,
fontSize: 10.sp,
fontWeight:
FontWeight.bold),
),
],
),
)
],
),
),
),
);
}),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
"Promo Mantap",
style: TextStyle(
color: const Color(0xffF0B900),
fontSize: 10.sp,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
],
);
}),
),
);
}
also my index.dart (botnav)
class Index extends StatefulWidget {
const Index({Key? key}) : super(key: key);
#override
_IndexState createState() => _IndexState();
}
class _IndexState extends State<Index> {
int _currentIndex = 0;
final List<Widget> _container = [
const HomeScreen(),
const PromoScreen(),
const BookingStatusScreen(),
];
#override
Widget build(BuildContext context) {
return Scaffold(
body: _container[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: const Color(0xffF0B900),
unselectedItemColor: const Color(0xffAFAFAF),
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
items: const [
BottomNavigationBarItem(
icon: Icon(
Icons.home,
),
label: "Beranda",
),
BottomNavigationBarItem(
icon: Icon(
Icons.price_change_outlined,
),
label: "Promo",
),
BottomNavigationBarItem(
icon: Icon(
Icons.receipt_long_rounded,
),
label: "Transaksi",
),
])
);
}
}
Any help will be appreciated, Thank you.

How to display image from Strapi into Flutter Application

I have created strapi account and I want to load image from strapi Headless CMS to Flutter application. I am able to load data like bank name and descriptions, but I can't load image from strapi using http and getAll(). I'm not getting any error but I can't load image from strapi. Can you help me?
MY CODE IS HERE: (If you want, I can add imported libraries.)
`import 'package:flutter/material.dart';
import 'package:horizon/models/journey.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';
class JourneyPage extends StatefulWidget {
#override
_JourneyPageState createState() => _JourneyPageState();
}
class _JourneyPageState extends State<JourneyPage> {
//Journeys journeys = Journeys(0, '', '', '');
List<Journey> journeys = [];
Future getAll() async {
var data = await http.get('http://localhost:1337/apis/');
var jsonData = json.decode(data.body);
for (var u in jsonData) {
journeys.add(
Journey(u['id'], u['imageUrl'], u['journeyName'], u['description']));
}
return journeys;
}
#override
Widget build(BuildContext context) {
return Container(
height: 400.0,
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Journeys.',
style: TextStyle(
fontFamily: 'AvenirNextLTPro',
fontSize: 24.0,
letterSpacing: 1.5,
fontWeight: FontWeight.bold,
color: Colors.black),
),
ElevatedButton(
onPressed: () {
print('View all');
},
style: ElevatedButton.styleFrom(
side: BorderSide(color: Colors.black, width: 1.0),
primary: Colors.black),
child: Text(
'VIEW ALL',
style: TextStyle(
fontFamily: 'AvenirNextLTPro',
fontSize: 12.0,
letterSpacing: 1.5,
color: Colors.white),
),
),
],
),
),
SizedBox(height: 30.0),
Container(
margin: EdgeInsets.only(left: 12, right: 4),
height: 260.0,
color: Colors.white,
child: FutureBuilder(
future: getAll(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: Text('Loading...'),
));
} else {
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return Container(
width: 260.0,
margin: EdgeInsets.only(left: 12.0, right: 8.0),
decoration: BoxDecoration(
border: Border.all(width: 1.0, color: Colors.grey),
),
child: Stack(
alignment: Alignment.topCenter,
children: [
Positioned(
bottom: 15.0,
child: Container(
width: 240.0,
height: 49.0,
color: Colors.white,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(snapshot.data[index].journeyName,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.normal,
letterSpacing: 1.1,
color: Colors.black)),
Text(
snapshot.data[index].description,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16.0,
color: Colors.black),
),
],
),
Icon(
Icons.bookmark_border,
size: 38,
color: Colors.black,
),
],
),
),
),
Container(
child: Stack(children: [
Image(
height: 260.0,
width: 260.0,
image:
AssetImage(snapshot.data[index].imageUrl),
),
]),
),
],
),
);
},
);
}
},
),
)
],
),
);
}
}
`
Here my class model
class Journey {
int id;
String imageUrl;
String journeyName;
String description;
Journey(
this.id,
this.imageUrl,
this.journeyName,
this.description,
);
}
Maybe works if you use Image.network() instead of AssetImage(), like this:
Image.network(url)

how to add fixed container above x number of scrollable card

I am trying to add a fixed buildHelpCard(context, alldata) above the scrollable list but whenever I try to add the buildHelpCard the list got disappeared and only the buildHelpCard is showing ... can you guys please suggest me how to fix this issues
**here is my code**
```
import 'package:flutter/material.dart';
import '../colors/constants.dart';
import 'package:get/get.dart';
import 'package:flutter_svg/flutter_svg.dart';
class duesDetails extends StatefulWidget {
var data;
var count;
duesDetails(this.data, this.count);
#override
_duesDetailsState createState() => _duesDetailsState();
}
class _duesDetailsState extends State<duesDetails> {
#override
Widget build(BuildContext context) {
var alldata = widget.data; // added all value to data for easy access
int count = widget.count;
return Scaffold(
appBar: buildAppBar(alldata),
body: Container(
decoration: BoxDecoration(
color: kPrimaryColor.withOpacity(0.03),
),
child: Center(
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.only(
top: 22, bottom: 22, left: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
InkWell(
onTap: () {},
child: Text(
'${alldata[count]['pay list'][index]['discription']}',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 22),
),
),
Text(
'Capital',
style: TextStyle(color: Colors.grey.shade500),
),
],
),
Container(
height: 30,
width: 50,
child: Image.asset('assets/facebook.png'),
)
],
),
),
);
},
itemCount: alldata[count]['pay count'] == null ? 0 : alldata[count]['pay count'],
),
),
),
);
}
AppBar buildAppBar(var data) {
return AppBar(
backgroundColor: kPrimaryColor.withOpacity(.05),
elevation: 0,
//title: Obx(() => Text('Randas ', style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),),),
title: Text("${data[0]['name']} Pay Details", style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),),
iconTheme: IconThemeData(
color: kPrimaryColor,
size: 28.0,
),
);
}
Container buildHelpCard(BuildContext context, var data) {
return Container(
height: 150,
width: double.infinity,
child: Stack(
alignment: Alignment.bottomLeft,
children: <Widget>[
Container(
padding: EdgeInsets.only(
// left side padding is 40% of total width
left: MediaQuery.of(context).size.width * .4,
top: 20,
right: 20,
),
height: 130,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF60BE93),
Color(0xFF1B8D59),
],
),
borderRadius: BorderRadius.circular(20),
),
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: "${data[5]["title"]}\n",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: Colors.white),
),
TextSpan(
text: "${data[5]["dis"]}",
style: TextStyle(
color: Colors.white.withOpacity(0.7),
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 210.0, 20.0),
child: SvgPicture.asset("assets/svg/friends.svg"),
),
],
),
);
}
}
```
NOTE - I want to add buildHelpCard(context, alldata) function above the start of the card list... but when I try to do this the list got disappeared
Try this
child: Column(
children: [
buildHelpCard()
Expanded(child:
ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.only(
top: 22, bottom: 22, left: 16, right: 16),
child:........

Define Number of lists according with Number into Widget flutter

What I Have are number of orders received that has be shown into a tab into a widget in flutter according with this code:
class ShipmentTab extends StatefulWidget {
#override
_ShipmentTabState createState() => _ShipmentTabState();
}
class _ShipmentTabState extends State<ShipmentTab> {
**final shipmentNumber = "16";**
#override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
color: Color(0xfffeaf0d),
child: Container(
width: 40,
height: 40,
child: Icon(
Icons.local_shipping,
color: Colors.white,
),
),
),
),
Padding(
padding: const EdgeInsets.all(13),
child: Text(
shipmentNumber,
style: TextStyle(
color: Colors.white, fontSize: 35, fontWeight: FontWeight.bold),
),
),
],
);
}
}
as you can see variable is " shipmentNumber " that show "16"
below I have listview.builder and I need to add itemCount and this count has to be refered to the tab above "16"
this is the code of the list:
Container(
height: 400,
child: ListView.builder(
shrinkWrap: true,
itemBuilder: (ctx, int) {
return Card(
color: Color(0xFF1f2032),
elevation: 15,
child: Container(
width: 60,
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Card(
color: Color(0xfffeaf0d),
child: Container(
height: 40,
width: 40,
child: Icon(
Icons.local_shipping,
color: Colors.white,
size: 25,
)),
),
Text(
'Ref № $int',
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
'Mario Rossi',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color(0xfffeaf0d),
),
),
Text(
'Consegnato',
style: TextStyle(color: Colors.lightGreenAccent),
),
Icon(
Icons.share,
color: Colors.white,
)
],
),
),
);
},
),
),
],
);
}
}
ListView.builder has itemCount parameter. I notice shipmentNumber is in String so you can parse it to int. Also you need to remove the Container height wrapping your ListView
ListView.builder(
shrinkWrap: true,
itemCount: int.parse(shipmentNumber),
itemBuilder: (BuildContext context, int index) {
/** build your Item here **/
return BuiltItem();
},
)