i just started with flutter. in my case, i want to show 10 items listview on my home page. but that listview only shows 9 items. listview cannot be scrolled to show other item. can you see whats wrong with my code?
I have been looking for a solution to this problem by looking for a topic that has the same title, but nothing. i have changed some lines of my code but i get error "bottom overlow by 240px"
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
Future<Null> _fetchPartner() async {
print('Please Wait');
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent),
);
return Scaffold(
resizeToAvoidBottomInset: false,
body: RefreshIndicator(
onRefresh: _fetchPartner,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
physics: AlwaysScrollableScrollPhysics(),
child: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding:
const EdgeInsetsDirectional.only(top: 18, bottom: 18),
child: Text("Powered By:",
style: new TextStyle(fontSize: 18.0)),
)
],
),
ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: EdgeInsets.zero,
elevation: 0.4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
child: ListTile(
leading: CircleAvatar(
child: Image.network(
"https://via.placeholder.com/150")),
title: Text(
"Coconut Oil",
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold),
),
subtitle: Row(
children: <Widget>[
Icon(Icons.linear_scale,
color: Colors.greenAccent),
Text("Go Green!",
style:
TextStyle(color: Colors.black87))
],
),
trailing: Icon(Icons.keyboard_arrow_right,
color: Colors.black87, size: 30.0))));
})
],
),
),
));
}
}
Try below code Its working properly:
SingleChildScrollView(
child: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(top: 18, bottom: 18),
child: Text(
"Powered By:",
style: new TextStyle(fontSize: 18.0),
),
)
],
),
ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: EdgeInsets.zero,
elevation: 0.4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
child: ListTile(
leading: CircleAvatar(
child:
Image.network("https://via.placeholder.com/150")),
title: Text(
"Coconut Oil",
style: TextStyle(
color: Colors.black87, fontWeight: FontWeight.bold),
),
subtitle: Row(
children: <Widget>[
Icon(Icons.linear_scale, color: Colors.greenAccent),
Text(
"Go Green!",
style: TextStyle(color: Colors.black87),
)
],
),
trailing: Icon(
Icons.keyboard_arrow_right,
color: Colors.black87,
size: 30.0,
),
),
),
);
},
)
],
),
),
Your result screen:
Add this property to Listivew.Builder
physics : NeverScrollableScrollPhysics()
as it is inside SingleChildScrollView.
Add this line to your code.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
Future<Null> _fetchPartner() async {
print('Please Wait');
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent),
);
return Scaffold(
resizeToAvoidBottomInset: false,
body: RefreshIndicator(
onRefresh: _fetchPartner,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
physics: AlwaysScrollableScrollPhysics(),
child: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding:
const EdgeInsetsDirectional.only(top: 18, bottom: 18),
child: Text("Powered By:",
style: new TextStyle(fontSize: 18.0)),
)
],
),
ListView.builder(
padding: EdgeInsets.zero,
physics : NeverScrollableScrollPhysics()
shrinkWrap: true,
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: EdgeInsets.zero,
elevation: 0.4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
child: ListTile(
leading: CircleAvatar(
child: Image.network(
"https://via.placeholder.com/150")),
title: Text(
"Coconut Oil",
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold),
),
subtitle: Row(
children: <Widget>[
Icon(Icons.linear_scale,
color: Colors.greenAccent),
Text("Go Green!",
style:
TextStyle(color: Colors.black87))
],
),
trailing: Icon(Icons.keyboard_arrow_right,
color: Colors.black87, size: 30.0))));
})
],
),
),
));
}
}
Remove the singleChildScrollview and add a expanded widget on the listview.builder.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
Future<Null> _fetchPartner() async {
print('Please Wait');
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent),
);
return Scaffold(
resizeToAvoidBottomInset: false,
body: RefreshIndicator(
onRefresh: _fetchPartner,
child: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding:
const EdgeInsetsDirectional.only(top: 18, bottom: 18),
child: Text("Powered By:",
style: new TextStyle(fontSize: 18.0)),
)
],
),
Expanded(
child : ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: EdgeInsets.zero,
elevation: 0.4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
child: ListTile(
leading: CircleAvatar(
child: Image.network(
"https://via.placeholder.com/150")),
title: Text(
"Coconut Oil",
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold),
),
subtitle: Row(
children: <Widget>[
Icon(Icons.linear_scale,
color: Colors.greenAccent),
Text("Go Green!",
style:
TextStyle(color: Colors.black87))
],
),
trailing: Icon(Icons.keyboard_arrow_right,
color: Colors.black87, size: 30.0))));
})
],
),
),
));
}
}
Please try with this code
replace your body tag with this and let me know
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(top: 18, bottom: 18),
child:
Text("Powered By:", style: new TextStyle(fontSize: 18.0)),
)
],
) ,
Expanded ( child : ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: 13,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: EdgeInsets.zero,
elevation: 0.4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
child: ListTile(
leading: CircleAvatar(
child: Image.network(
"")),
title: Text(
"Coconut Oil",
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold),
),
subtitle: Row(
children: <Widget>[
Icon(Icons.linear_scale,
color: Colors.greenAccent),
Text("Go Green!",
style: TextStyle(color: Colors.black87))
],
),
trailing: Icon(Icons.keyboard_arrow_right,
color: Colors.black87, size: 30.0))));
}) )
]
)
I am not convinced that any of the provided solutions is the right one. All of them use shrinkWrap: true. With only 10 elements this should not impact performance, but when it changes to 10k, well it will be a problem. I would simplify the tree by removing SingleChildScrollView and Column, moving Row from Column to ListView.builder, and displaying it only when the index == 0. We need to remember to add 1 in itemCount and remove shrinkWrap. There is another solution with the use of SliverList, but it would complicate too much without additional benefits. Below is the code for the first solution.
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
Future<Null> _fetchPartner() async {
print('Please Wait');
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: RefreshIndicator(
onRefresh: _fetchPartner,
child: ListView.builder(
itemCount: 10 + 1,
itemBuilder: (BuildContext context, int index) {
if (index == 0) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(
top: 18, bottom: 18),
child: Text("Powered By:",
style: new TextStyle(fontSize: 18.0)),
)
],
);
}
return Card(
margin: EdgeInsets.zero,
elevation: 0.4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
child: ListTile(
leading: CircleAvatar(
child: Image.network(
"https://via.placeholder.com/150")),
title: Text(
"Coconut Oil",
style: TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold),
),
subtitle: Row(
children: <Widget>[
Icon(Icons.linear_scale,
color: Colors.greenAccent),
Text("Go Green!",
style: TextStyle(color: Colors.black87))
],
),
trailing: Icon(Icons.keyboard_arrow_right,
color: Colors.black87, size: 30.0))));
}),
));
}
}
Related
I am developing an app with flutter and I am getting an error about height.
I have a listview.separated and I have a SingleChildScrollView. I am getting flex error.
This is my file to align widgets inside Scaffold and SafeArea. I have a file for runApp but it is not important for the question.
class ProfilePageC extends StatelessWidget {
const ProfilePageC({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
AboutTopBarW(), // It has not listview
ImageFieldW(), // It has no listview
PercentsW(), //It has no listview
HomeArticleList2W() //It has a listview.separated
],
),
),
),
);
}
}
this is my file for listview.separated widget.
class HomeArticleList2W extends ConsumerWidget {
const HomeArticleList2W({Key? key}) : super(key: key);
#override
Widget build(BuildContext context, WidgetRef ref) {
final futureCatFacts = ref.watch(multiFutureArticleProvider);
return Expanded(
child: futureCatFacts.when(
loading: () => const ShimmerHomeW(),
error: (err, stack) => Text('Error: $err'),
data: (data) {
final decodedData = json.decode(data.body);
return ListView.separated(
separatorBuilder: (BuildContext context, int index) {
if (index % 3 == 0) {
return const Divider();
}
return const Divider();
},
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: decodedData.length ,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(
left: 20,
right: 20,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
decodedData[index]['largeImage'].toString(),
fit: BoxFit.cover,
height: 70,
width: 70,
)),
const SizedBox(
width: 10,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
decodedData[index]['title'],
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.bold),
),
const SizedBox(
height: 5,
),
Row(
children: [
const Icon(
Icons.av_timer_sharp,
size: 20,
),
Text(decodedData[index]['date']),
],
),
],
),
),
const SizedBox(
width: 5,
),
const Icon(Icons.bookmark_border),
],
),
);
},
);
},
),
);
}
}
There is no error when I erase HomeArticleList2W() from the SingleChildScrollView. Therefore I thnink the error consist of the listview.separated.
How to solve this problem.
Remove the expanded widget and add mainAxisSize min
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
decodedData[index]['title'],
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.bold),
),
const SizedBox(
height: 5,
),
Row(
children: [
const Icon(
Icons.av_timer_sharp,
size: 20,
),
Text(decodedData[index]['date']),
],
),
],
),
Before displaying the code, here are the things that I checked to avoid similar answers :
android:extratNativeLibs="true"
Jsonfile firebase connected
routegenerator and initialroute checked in the main file and
generatorfile
.I like to avoid mediaQuery and work with percentages, that is why I use FractionallySizedBox. Here is the code of the initial route :
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Start extends StatelessWidget {
const Start({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.center,
child: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
FractionallySizedBox(widthFactor: 0.15, heightFactor: 0.15, child: Image.asset('assets/crown.png')),
FractionallySizedBox(
widthFactor: 0.40,
heightFactor: 0.20,
child: TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/items');
},
child: Container(
decoration: BoxDecoration(color: Colors.purple),
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
const Text('Start shopping',
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.italic,
fontSize: 25,
)),
Image.asset('assets/crown.png')
]))))
])))));
}
}
Warp your FractionallySizedBox with Expanded
Expanded(
child: FractionallySizedBox(
widthFactor: 0.15,
heightFactor: 0.15,
child: Image.asset('assets/crown.png')),
),
Expanded(
child: FractionallySizedBox(
widthFactor: 0.40,
heightFactor: 0.20,
child: TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/items');
},
child: Container(
decoration: BoxDecoration(color: Colors.purple),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Start shopping',
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.italic,
fontSize: 25,
)),
Image.asset('assets/crown.png')
],
),
),
),
),
),
The space between tab bar view and bottom navigation bar is the extra space that I want to remove.
in the image, you can see the space that shouldn't be there
class Tab_Bar2 extends StatefulWidget {
const Tab_Bar2({Key? key}) : super(key: key);
#override
_Tab_Bar2State createState() => _Tab_Bar2State();
}
class _Tab_Bar2State extends State<Tab_Bar2> with SingleTickerProviderStateMixin {
final bodyGlobalKey = GlobalKey();
final List<Widget> myTabs = [
Text(..),
Text(..),
Text(..),
Text(..),
Text(..),
Text(..),
];
late TabController _tabController;
late ScrollController _scrollController;
#override
void initState() {
_scrollController = ScrollController();
_tabController = TabController(length: 6, vsync: this);
super.initState();
}
#override
void dispose() {
_tabController.dispose();
_scrollController.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Dashboard"),
centerTitle: true,
backgroundColor: const Color(0xffFFC36A),
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.notifications),
),
]),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
decoration: BoxDecoration(
color: Color(0xffFFC36A),
),
child: Padding(
padding: EdgeInsets.only(top: 20.0, left: 60),
child: Text(
'Drawer',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
),
),
ListTile(
title: const Text('Log Out'),
onTap: () {
},
),
ListTile(
title: const Text('Item 2'),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
body: NestedScrollView(
controller: _scrollController,
headerSliverBuilder: (BuildContext context, value) {
return [
SliverToBoxAdapter(child: Column(
children: [img1(), grid(), rsp(), LiveChart()],
),),
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 15,vertical: 15),
child: Text('Latest',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
fontFamily: 'railway',
color: Theme_Data.font_color,
),
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 3.5),
padding: EdgeInsets.symmetric(horizontal: 2.5,vertical: 2.5),
height: 35,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade200),
borderRadius: BorderRadius.all(
Radius.circular(25),
),
),
child: TabBar(
controller: _tabController,
labelPadding: EdgeInsets.symmetric(horizontal: 2.0, vertical: 5),
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(50), // Creates border
color: Theme_Data.th_light_color),
tabs: myTabs,
),
),
],
),
),
];
},
body: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Theme(
data: Theme.of(context).copyWith(
dividerColor: Colors.white
),
child: TabBarView(
controller: _tabController,
children: <Widget>[
SalesTable(),
QuotationsTable(),
PurchasesTable(),
TransfersTable(),
ConsumersTable(),
SuppliersTable(),
],
),
),
),
),
);
}
}
in above code i think there might be the issues between the usage of SviverToBoxAdapter what widget should i use instead to achieve the required design
I am using Cupertino Segmente Control , I created a tab using three swings and assigned three widgets to the front page body. When selecting any of the tabs, it displays the body of the new widget. So far, everything works fine. Products are loaded inside each page, and when we select a product, it must go to the second page .The second page opens, but inside the body of the first page. If you help me, thank you very much
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int groohEntkhabi = 1;
final Map<int, Widget> logoBala = const <int, Widget>{
0: Text("کشاورزی" ,style: TextStyle(fontSize: 14),),
1: Text("خرید فروش" ,style: TextStyle(fontSize: 14),),
2: Text("رهن و اجاره" ,style: TextStyle(fontSize: 14),),
};
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
iconTheme: IconThemeData(color: Colors.blue),
//centerTitle: true,
title: Container(
child: Row(
children: [
Expanded(
child: CupertinoSegmentedControl(
padding: EdgeInsets.all(0.0),
groupValue: groohEntkhabi,
onValueChanged: (changeFromGroupValue) {
setState(() {
groohEntkhabi = changeFromGroupValue;
});
},
children: logoBala,
),
),
],
)
),
actions: [
IconButton(icon: Icon(Icons.search), onPressed: (){}),
],
),
drawer: MyDraver(),
bottomNavigationBar: MyBottomNavigation(),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {}, label: Text("ثبت رایگان آگهی",style: TextStyle(color: Colors.white),), icon:Icon(Icons.add,color: Colors.white,),backgroundColor: Colors.blue,
),
// floatingActionButton: FloatingActionButton(onPressed: (){
// // Navigator.of(context).push(MaterialPageRoute(
// // builder: (context) => Shoab()
// // ));
// },
// shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
// backgroundColor: Colors.deepOrange,
// child:Center(child: Text("ثبت رایگان آگهی")),),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
body:
(
_childern(groohEntkhabi)
),
),
);
}
Widget _childern(index){
List<Widget> page_screen=[];
page_screen.add(_keshavarzi());
page_screen.add(kharidFroosh());
page_screen.add(_ejare());
return page_screen[index];
}
Widget kharidFroosh(){
return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: [
// ... app-specific localization delegate[s] here
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''), // farsi
],
home: ListView.builder(padding: EdgeInsets.only(top: 3.0,left: 3.0,right: 3.0),
itemBuilder: mycard_view1,itemCount: 5,));
}
Widget mycard_view1(BuildContext context ,int index){
String mogheiatt ="کوی ملا نفس";
String mogheiat = mogheiatt.length>14 ? mogheiatt.substring(0,14):mogheiatt;
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),),
elevation: 1.0,
//color: Colors.blue,
child: InkWell(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => Safhe2_kharid_froosh()));
},
child: Stack(
children: <Widget> [
Container(margin: EdgeInsets.fromLTRB(50.0, 5.0, 5.0, 5.5),
height: 160.0,
width: double.infinity,
decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(20.0)),
child: Padding(
padding: EdgeInsets.fromLTRB(100.0,10.0,10.0,2.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text("فروش ویلایی",style: TextStyle(fontFamily: "shabnammedium",fontSize: 15.0),),
SizedBox(
height: 7.0,
),
Text("قیمت : 850 م تومان",style: TextStyle(fontFamily: "shabnammedium",fontSize: 15.0),),
SizedBox(
height: 7.0,
),
Text("متراژ : 85 متر ",style: TextStyle(fontFamily: "shabnammedium",fontSize: 15.0),),
SizedBox(
height: 30.0,
),
Row(
//crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(color: Color(0xffe1f5fe),borderRadius: BorderRadius.circular(10.0),),
child: Center(child: Padding(
padding: EdgeInsets.only(left: 3.0,right: 3.0),
child: Row(
children: [
Text("روز پیش",style: TextStyle(fontFamily: "shabnamlight",color: Colors.black87),),
Text("5",style: TextStyle(fontFamily: "shabnamlight",color: Colors.black87),),
],
),
)),
// width: 70.0,
),
Container(
child: Row(
children: [
Text("...",style: TextStyle(fontFamily: "shabnamlight",color: Colors.black87),),
Text(mogheiat,style: TextStyle(fontFamily: "shabnamlight",color: Colors.black87),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
//width: 100.0,
),
],
),
],
),
),
),
Positioned(
left: 10.0,
top: 5.0,
bottom: 5.0,
child: ClipRRect(borderRadius: BorderRadius.circular(15.0),
child:Image.asset("images/home.jpg",width: 130,fit: BoxFit.cover,),
),
),
],
),
),
);
}
Widget _keshavarzi(){
return Keshavarzi();
}
Widget _ejare(){
return Ejare();
}
}
this is my images app
this is my secend page inside a first page body
and this my first pages
I am developing a flutter based app and studied there are couple of ways to add splash screen. But I am not sure which one is the best to achieve.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:mingup/screen/login_screen.dart';
// This is the Splash Screen
class SplashScreen extends StatefulWidget {
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> with SingleTickerProviderStateMixin{
AnimationController _animationController;
Animation<double> _animation;
#override
void initState() {
// TODO: implement initState
super.initState();
_animationController = new AnimationController(
vsync: this,
duration: new Duration(milliseconds: 500)
);
_animation = new CurvedAnimation(
parent: _animationController,
curve: Curves.easeOut,
);
_animation.addListener(()=> this.setState((){}));
_animationController.forward();
Timer(Duration(seconds: 10), (){
Navigator.push(context, MaterialPageRoute(builder: (context) => LoginScreen()));
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
child: Image.asset(
'images/splashscreenbg.png',
fit: BoxFit.cover,
)
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 2,
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlutterLogo(
size: _animation.value * 100.0,
),
Padding(padding: EdgeInsets.only(top: 10.0)),
Text("MingUp", style: TextStyle(color: Colors.white, fontSize: 24.0, fontWeight: FontWeight.bold),)
],
),
),
),
]
)
],
),
);
}
}
You can add just a simple splash screen which can navigate to the next screen after 5 seconds.
import 'package:flutter/material.dart';
import 'dart:async';
class SplashScreen extends StatefulWidget {
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
#override
void initState() {
super.initState();
Timer(
Duration(seconds: 5),
() => Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => Home())));
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(20, 172, 168, 1),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 2,
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.white,
radius: 60.0,
child: new Image.asset(
'assets/images/tree.jpg',
width: 70,
height: 90,
)),
Padding(
padding: EdgeInsets.only(top: 10.0),
),
Text(
'Your Text here!!',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24.0),
)
],
),
),
),
Expanded(
flex: 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
Padding(
padding: EdgeInsets.only(top: 20.0),
),
Text(
'Your Text here!!',
softWrap: true,
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white),
)
],
),
)
],
)
],
),
);
}
}