Text disappears when opening Dart Flutter Keyboard - flutter

I have a sign up screen like this:
When the keyboard is opened to enter information into the textFormFields here, the screen looks like this:
The text "Welcome to register form" disappeared. What is the cause of this problem? How can I solve it? Thanks in advance for the help.
Codes:
main.dart:
import 'package:flutter/material.dart';
import 'package:simto_todolist/app.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: splashScreen(),
);
}
}
app.dart:
import 'package:flutter/material.dart';
import 'package:cool_alert/cool_alert.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:timer_count_down/timer_count_down.dart';
import 'package:group_button/group_button.dart';
import 'package:firebase_auth/firebase_auth.dart';
var currentPage;
class splashScreen extends StatefulWidget {
#override
State<splashScreen> createState() => _splashScreenState();
}
final CarouselController _pageController = CarouselController();
class _splashScreenState extends State<splashScreen> {
List splashs = [sp1(), sp2(), sp3()];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Image.asset("logo.png", fit: BoxFit.cover, height: 75,),
centerTitle: true,
backgroundColor: Colors.white,
elevation: 0,
),
backgroundColor: Colors.white,
body: CarouselSlider(
carouselController: _pageController,
items: splashs.map((i) {
return Builder(
builder: (BuildContext context) {
return i;
},
);
}).toList(),
options: CarouselOptions(
height: MediaQuery.of(context).size.height,
viewportFraction: 1,
enableInfiniteScroll: false,
onPageChanged: (index, reason) {
setState(() {
currentPage = index;
print(currentPage);
});
},
),
)
);
}
}
class sp1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height / 5
),
Image.asset('assets/splash1.png', fit: BoxFit.cover, height: 220,),
Text("Hoş geldin!", style: TextStyle(fontSize: 25, fontFamily: "Roboto-Bold"),),
SizedBox(height: 15),
Expanded(child: Text("Simto: To-do-list uygulamasına hoş geldin.", style: TextStyle(fontSize: 19, fontFamily: "Roboto-Thin"),)),
RaisedButton(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.arrow_forward, color: Colors.white,),
SizedBox(width: 10),
Text("Devam", style: TextStyle(color: Colors.white, fontSize: 20, fontFamily: "Roboto-Thin"),),
],
),
),
color: Colors.blue[400],
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
onPressed: () {
_pageController.nextPage(duration: Duration(milliseconds: 500), curve: Curves.easeIn);
},
),
SizedBox(height: 18),
]
);
}
}
class sp2 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height / 5
),
Image.asset('assets/splash2.png', fit: BoxFit.cover, height: 235,),
Text("Yapılacakları planlayın", style: TextStyle(fontSize: 25, fontFamily: "Roboto-Bold"),),
SizedBox(height: 15),
Expanded(child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white,
),
child: Text("Düzenli bir gün, yapılacaklar listesi hazırlamakla başlar. Hemen yapılacaklar listesi oluşturun!", style: TextStyle(fontSize: 18, fontFamily: "Roboto-Thin"), textAlign: TextAlign.center,))),
SizedBox(height: 25),
RaisedButton(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.arrow_forward, color: Colors.white,),
SizedBox(width: 10),
Text("Devam", style: TextStyle(color: Colors.white, fontSize: 20, fontFamily: "Roboto-Thin"),),
],
),
),
color: Colors.blue[400],
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
onPressed: () {
_pageController.nextPage(duration: Duration(milliseconds: 500), curve: Curves.easeIn);
},
),
SizedBox(height: 18),
]
);
}
}
class sp3 extends StatefulWidget {
#override
State<sp3> createState() => _sp3State();
}
class _sp3State extends State<sp3> {
#override
Widget build(BuildContext context) {
return Column(
children: [
Image.asset('assets/splash3.png', fit: BoxFit.cover, height: 220,),
Text("Register", style: TextStyle(fontSize: 25, fontFamily: "Roboto-Bold"),), // Kayıt ol
SizedBox(height: 15),
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white,
),
child: Text("Welcome to register form", style: TextStyle(fontSize: 18, fontFamily: "Roboto-Thin"), textAlign: TextAlign.center,))), // Hemen kayıt ol ve yapılacaklar listeni hazırla!
SizedBox(height: 25),
Padding(
padding: const EdgeInsets.only(left: 11, right: 11),
child: TextFormField(
decoration: InputDecoration(
hintText: "E-mail",
labelStyle: TextStyle(fontSize: 18, fontFamily: "Roboto-Thin", color: Colors.grey),
prefixIcon: Icon(Icons.email, color: Colors.grey,),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
)
),
style: TextStyle(
color: Colors.black,
fontSize: 20
),
),
),
SizedBox(height: 10,),
Padding(
padding: const EdgeInsets.only(left: 11, right: 11),
child: TextFormField(
decoration: InputDecoration(
hintText: "Name-surname", // Ad-soyad
labelStyle: TextStyle(fontSize: 18, fontFamily: "Roboto-Thin", color: Colors.grey),
prefixIcon: Icon(Icons.person, color: Colors.grey, size: 30,),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
),
),
style: TextStyle(
color: Colors.black,
fontSize: 20
),
),
),
// şifre input:
SizedBox(height: 10,),
Padding(
padding: const EdgeInsets.only(left: 11, right: 11),
child: TextFormField(
decoration: InputDecoration(
hintText: "Password", // Şifre
labelStyle: TextStyle(fontSize: 18, fontFamily: "Roboto-Thin", color: Colors.grey),
prefixIcon: Icon(Icons.lock, color: Colors.grey,),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
),
suffixIcon: InkWell(
child: Icon(Icons.remove_red_eye),
)
),
style: TextStyle(
color: Colors.black,
fontSize: 20
),
obscureText: true,
),
),
SizedBox(height: 25,),
RaisedButton(
child: Text("Register"),
onPressed: () {
}
),
],
);
}
}
class loadingAccount extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/splash4.png', fit: BoxFit.cover, height: 200,),
SizedBox(height: 15),
Text("Her şey size özel hazırlanıyor..", style: TextStyle(fontSize: 22, fontFamily: "Roboto-Medium"), textAlign: TextAlign.center,),
SizedBox(height: 15),
CircularProgressIndicator(),
Countdown(
seconds: 4,
interval: Duration(milliseconds: 500),
build: (BuildContext context, double time) {
return SizedBox();
},
onFinished: () {
//register();
print("bitti");
Navigator.push(context,
PageRouteBuilder(
barrierDismissible: false,
opaque: true,
transitionDuration: Duration(milliseconds: 150),
transitionsBuilder: (BuildContext context, Animation<double> animation, Animation <double> secAnimation, Widget child) {
return ScaleTransition(
alignment: Alignment.center,
scale: animation,
child: child,
);
},
pageBuilder: (BuildContext context, Animation<double> animation, Animation <double> secAnimation) {
// return HomePage();
}
),
);
},
),
WillPopScope(
child: Container(),
onWillPop: () {
return Future.value(false);
},
)
],
),
),
);
}
}
My goal is to create a nice sign up screen.

Try wrapping your column with a SingleChildScrollView in SP3 as follows:
return SingleChildScrollView(
child: Column(
children: [<COLUMN-CHILDREN>]
),
);
This will allow your column to expand to its full minimum MainAxisSize when the keyboard is shown, instead of trying to squeeze all the elements onto the screen

Related

Error: Could not find the correct Provider<Controller> above this DashBoardScreen Widget

This happens because you used a BuildContext that does not include the provider
of your choice. There are a few common scenarios:
You added a new provider in your main.dart and performed a hot-reload.
To fix, perform a hot-restart.
The provider you are trying to read is in a different route.
Providers are "scoped". So if you insert of provider inside a route, then
other routes will not be able to access that provider.
You used a BuildContext that is an ancestor of the provider you are trying to read.
Make sure that DashBoardScreen is under your MultiProvider/Provider.
This usually happens when you are creating a provider and trying to read it immediately.
For example, instead of:
Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
// Will throw a ProviderNotFoundError, because `context` is associated
// to the widget that is the parent of `Provider<Example>`
child: Text(context.watch<Example>().toString()),
);
}
consider using builder like so:
Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
// we use `builder` to obtain a new `BuildContext` that has access to the provider
builder: (context, child) {
// No longer throws
return Text(context.watch<Example>().toString());
}
);
}
Here i have attached main dart file.
import 'package:device_preview/device_preview.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:lifemaster/Components/app_constants.dart';
import 'package:lifemaster/Components/app_theme.dart';
import 'package:lifemaster/Screens/Dashboard/controllers/controller.dart';
import 'package:lifemaster/utility/language/localization_service.dart';
import 'package:lifemaster/utility/provider_logger.dart';
import 'package:lifemaster/view_router.dart';
import 'package:lifemaster/view_routes.dart';
import 'package:provider/provider.dart';
void main() async{
WidgetsFlutterBinding.ensureInitialized();
runApp(
ProviderScope(
observers: [ ProviderLogger()],
child:DevicePreview(
enabled: false,
builder: (context) => MyApp() ,
)),
);
}
class MyApp extends HookWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return GetMaterialApp(
title: AppConstant.appTitle,
debugShowCheckedModeBanner: false,
theme: appPrimaryTheme(),
locale: LocalizationService.currentLocale,
fallbackLocale: LocalizationService.fallbackLocale,
translations: LocalizationService(),
initialRoute: ViewRoutes.initial,
getPages: ViewRouter.routes,
);
}
}
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lifemaster/CommonUi/responsive.dart';
import 'package:lifemaster/Components/app_styles.dart';
import 'package:lifemaster/Components/asset_images.dart';
import 'package:lifemaster/Components/palette.dart';
import 'package:lifemaster/viewModel/authenticationViewModel.dart';
import 'package:lifemaster/view_routes.dart';
class LoginScreen extends HookConsumerWidget {
const LoginScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context,WidgetRef ref) {
var _formKey = GlobalKey<FormState>();
var userNameController = TextEditingController();
var passwordController= TextEditingController();
final state = ref.watch(authenticationViewModel);
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return Scaffold(
backgroundColor: Palette.backColor,
body: SizedBox(
height: height,
width: width,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Responsive.isMobile(context) ? const SizedBox() : Expanded(
child: Container(
height: height,
color: Palette.backgroundColor,
child: Center(
child: Image.asset(AssetPNGImages.logop,
width: 300,
)
),
),
),
Expanded(
child: Container(
height: height,
margin: EdgeInsets.symmetric(horizontal: Responsive.isMobile(context)? height * 0.032 : height * 0.12),
color: Palette.backColor,
child: SingleChildScrollView(
padding: const EdgeInsets.only(bottom: 40.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(height: height * 0.2),
SizedBox(height: height * 0.02),
SizedBox(height: height * 0.064),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Text('User Name',
style: ralewayStyle.copyWith(
fontSize: 14.0,
color: Palette.textBlackTitle,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(height: 6.0),
Container(
height: 50.0,
width: width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
color: Palette.textBox,
),
child: TextFormField(
cursorColor: Palette.appColor,
controller: userNameController,
style: ralewayStyle.copyWith(
fontWeight: FontWeight.w400,
color: Colors.black,
fontSize: 12.0,
),
decoration: InputDecoration(
border: InputBorder.none,
prefixIcon: const Icon(
Icons.account_circle,
color: Palette.appColor,
),
contentPadding: const EdgeInsets.only(top: 16.0),
hintText: 'Enter User Name',
hintStyle: ralewayStyle.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12.0,
),
),
),
),
SizedBox(height: height * 0.014),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Text('Password',
style: ralewayStyle.copyWith(
fontSize: 14.0,
color: Palette.textBlackTitle,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(height: 6.0),
Container(
height: 50.0,
width: width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
color: Palette.textBox,
),
child: TextFormField(
cursorColor: Palette.cursor,
controller: passwordController,
style: ralewayStyle.copyWith(
fontWeight: FontWeight.w400,
/* color: AppColors.blueDarkColor,*/
fontSize: 12.0,
),
obscureText: true,
decoration: InputDecoration(
border: InputBorder.none,
suffixIcon: IconButton(
onPressed: (){
},
icon: const Icon(
Icons.visibility_off,
color: Palette.icon,
),
),
prefixIcon: const Icon(
Icons.lock,
color: Palette.icon,
),
contentPadding: const EdgeInsets.only(top: 16.0),
hintText: 'Enter Password',
hintStyle: ralewayStyle.copyWith(
fontWeight: FontWeight.w400,
/*color: AppColors.blueDarkColor.withOpacity(0.5),*/
fontSize: 12.0,
),
),
),
),
SizedBox(height: height * 0.03),
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: (){},
child: Text('Forgot Password?',
style: ralewayStyle.copyWith(
fontSize: 12.0,
color: Colors.black,
fontWeight: FontWeight.w600,
),
),
),
),
SizedBox(height: height * 0.05),
Material(
color: Colors.transparent,
child: InkWell(
onTap: (){
/*if(_formKey.currentState!.validate()){
ref.read(authenticationViewModel.notifier).apiLoginCall(LoginRequestModel(userName: userNameController.text.toString(),password: passwordController.text.toString()));
}*/
//if(state is SuccessState){
Navigator.pushNamed(context, ViewRoutes.dashBoardPage);
// }
},
borderRadius: BorderRadius.circular(16.0),
child: Ink(
padding: const EdgeInsets.symmetric(horizontal: 70.0, vertical: 18.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
color: Palette.button,
),
child: Text('Login',
style: ralewayStyle.copyWith(
fontWeight: FontWeight.w700,
color: Palette.textSubTitleWhite,
fontSize: 16.0,
),
),
),
),
),
],
),
),
),
),
),
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:lifemaster/CommonUi/responsive.dart';
import 'package:lifemaster/Screens/Dashboard/components/dashboard_content.dart';
import 'package:lifemaster/Screens/Dashboard/constants/constants.dart';
import 'package:lifemaster/Screens/Dashboard/controllers/controller.dart';
import 'package:provider/provider.dart';
import 'components/drawer_menu.dart';
class DashBoardScreen extends StatelessWidget {
const DashBoardScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: bgColor,
drawer: const DrawerMenu(),
key: context.read<Controller>().scaffoldKey,
body: SafeArea(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (Responsive.isDesktop(context)) const Expanded(child: DrawerMenu(),),
const Expanded(
flex: 5,
child: DashboardContent(),
)
],
),
),
);
}
}

is there any way to validate Textfield in bottomsheet?

I want to validate my textfield(not textFormField) which is in bottomsheet, if textfield is empty it should shows error when I pressed the save button.
I used below code the problem with the code is it shows error only when I press on save button and should close the bottomsheet and when I open bottomsheet then it will show error.
Is there any way to validate the textfield on pressing save button and without closing the bottomsheet.
Thanks in advance.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: AddAddress()));
class AddNotes extends StatefulWidget {
#override
AddAddressState createState() => AddAddressState();
}
class AddAddressState extends State<AddAddress> {
final _text = TextEditingController();
bool _validate = false;
#override
void dispose(){
_text.dispose();
super.dispose();
}
bottomSheet() {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * 0.85,
decoration: new BoxDecoration(
color: Colors.transparent,
),
child: Container(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text("Address",
textScaleFactor: 1.3,
style: TextStyle(
fontSize: 18,
fontFamily: 'SFProDisplay',
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
letterSpacing: 0.45),
textAlign: TextAlign.center),
Container(
height: 215,
decoration: BoxDecoration(
color: Color(0x7feff1f5),
borderRadius: BorderRadius.circular(6),
),
padding: EdgeInsets.fromLTRB(17, 16, 17, 25),
child: new ConstrainedBox(
constraints: BoxConstraints(maxHeight: 200.0),
child: new Scrollbar(
child: new SingleChildScrollView(
scrollDirection: Axis.vertical,
reverse: true,
child: SizedBox(
height: 175.0,
child: new TextField(
controller: _text,
maxLines: 100,
decoration: InputDecoration(
hintText: "Address",
hintStyle: TextStyle(
color: Color(0x00FFa6a9af),
),
border: InputBorder.none,
errorText: _validate ? 'Notes can\'t be Empty' : null,
),
style: TextStyle(
height: 1.4,
fontSize: 16,
color: Colors.black,
fontFamily: 'regular',
letterSpacing: 0.35,
fontWeight: FontWeight.w400,
),
),
),
),
),
)),
Container(
height: 50,
color: Colors.transparent,
padding: EdgeInsets.fromLTRB(0, 0, 188, 0),
child:ElevatedButton(
child: Text('Save'),
onPressed: (){
setState(() {
_text.text.isEmpty ? _validate = true : _validate = false;
});
},
style: ElevatedButton.styleFrom(
primary: Colors.redAccent,
onPrimary: Colors.white,
textStyle: TextStyle(
fontFamily: 'regular',
fontSize: 16.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),),
),
),
],
),
));
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
title: Text(
"",
style: TextStyle(color: Colors.black87, fontFamily: "regular"),
textAlign: TextAlign.left,
),
centerTitle: false,
),
body: Center(
child: TextButton(
onPressed: () {
bottomSheet();
},
child: Text("AddAddress"),
),
),
);
}
}
As I checked it is because it doesn't properly rebuild so you have to close it then open it so the state that is change would effect.
I have added a changeNotifier class to keep the state and notify its listeners using provider package you can take look at it:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() => runApp(MaterialApp(home: AddAddress()));
class AddAddress extends StatefulWidget {
#override
AddAddressState createState() => AddAddressState();
}
class AddAddressState extends State<AddAddress> {
#override
void dispose(){
super.dispose();
}
bottomSheet() {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return ChangeNotifierProvider(create: (context) => CustomProvider(),child: CustomTextField());
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
title: Text(
"",
style: TextStyle(color: Colors.black87, fontFamily: "regular"),
textAlign: TextAlign.left,
),
centerTitle: false,
),
body: Center(
child: TextButton(
onPressed: () {
bottomSheet();
},
child: Text("AddAddress"),
),
),
);
}
}
class CustomTextField extends StatelessWidget{
#override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * 0.85,
decoration: new BoxDecoration(
color: Colors.transparent,
),
child: Container(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text("Address",
textScaleFactor: 1.3,
style: TextStyle(
fontSize: 18,
fontFamily: 'SFProDisplay',
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
letterSpacing: 0.45),
textAlign: TextAlign.center),
Container(
height: 215,
decoration: BoxDecoration(
color: Color(0x7feff1f5),
borderRadius: BorderRadius.circular(6),
),
padding: EdgeInsets.fromLTRB(17, 16, 17, 25),
child: new ConstrainedBox(
constraints: BoxConstraints(maxHeight: 200.0),
child: new Scrollbar(
child: new SingleChildScrollView(
scrollDirection: Axis.vertical,
reverse: true,
child: Consumer<CustomProvider>(
builder: (context, item, child) => SizedBox(
height: 175.0,
child: new TextField(
controller: Provider.of<CustomProvider>(context, listen: false).text,
maxLines: 100,
decoration: InputDecoration(
hintText: "Address",
hintStyle: TextStyle(
color: Color(0x00FFa6a9af),
),
border: InputBorder.none,
errorText: item.validate ? 'Notes can\'t be Empty' : null,
),
style: TextStyle(
height: 1.4,
fontSize: 16,
color: Colors.black,
fontFamily: 'regular',
letterSpacing: 0.35,
fontWeight: FontWeight.w400,
),
),
),
),
),
),
)),
Container(
height: 50,
color: Colors.transparent,
padding: EdgeInsets.fromLTRB(0, 0, 188, 0),
child:ElevatedButton(
child: Text('Save'),
onPressed: (){
Provider.of<CustomProvider>(context, listen: false).checkValidation();
},
style: ElevatedButton.styleFrom(
primary: Colors.redAccent,
onPrimary: Colors.white,
textStyle: TextStyle(
fontFamily: 'regular',
fontSize: 16.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),),
),
),
],
),
));
}
}
class CustomProvider extends ChangeNotifier{
final text = TextEditingController();
bool validate = false;
void checkValidation(){
if(text.text.isEmpty){
validate = true;
}else{
validate = false;
}
notifyListeners();
}
}

The method 'RippleIndicator' isn't defined for the type '_MyCardWidgetState'

I am trying to add google maps to my app. but I'm getting method isn't defined error.
ERRORS:
The method 'RippleIndicator' isn't defined for the type '_MyCardWidgetState'.
Try correcting the name to the name of an existing method, or defining a method named
'RippleIndicator'.
The method 'mapWidget' isn't defined for the type '_MyCardWidgetState'.
Try correcting the name to the name of an existing method, or defining a method named
'mapWidget'.
The value of the field '_child' isn't used.
Try removing the field, or using it.
Full code of my dart file
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'add_new.dart';
class CompanyDataBody extends StatelessWidget {
CompanyDataBody({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
backgroundColor: Colors.white,
centerTitle: true,
leading: Padding(
padding: EdgeInsets.only(left: 12),
child: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => AddNewBody()),
),
),
),
title: Text(
"COMPANY DATA",
style: TextStyle(
color: Color(4293492024),
),
),
actions: <Widget>[
IconButton(
icon: Image.asset('assets/icons/download_logo.png'),
tooltip: 'Download logo',
onPressed: () {},
),
],
),
//backgroundColor: Colors.yellow,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/main_bottom.png"),
alignment: Alignment.bottomCenter,
fit: BoxFit.cover,
),
),
child: MyCardWidget(),
),
),
);
}
}
/// This is the stateless widget that the main application instantiates.
class MyCardWidget extends StatefulWidget {
MyCardWidget({Key key}) : super(key: key);
#override
_MyCardWidgetState createState() => _MyCardWidgetState();
}
class _MyCardWidgetState extends State<MyCardWidget> {
Set<Marker> _createMarker() {
return <Marker>[
Marker(
markerId: MarkerId("current_location"),
position: LatLng(position.latitude, position.longitude),
icon: BitmapDescriptor.defaultMarker,
infoWindow: InfoWindow(title: "Current Location"),
),
].toSet();
}
// ignore: unused_field
GoogleMapController _controller;
Position position;
Widget _child;
#override
void initState() {
//Todo: implement initState
_child = RippleIndicator("Getting Location");
getCurrentLocation();
super.initState();
}
void getCurrentLocation() async {
Position res = await Geolocator().getCurrentPosition();
setState(() {
position = res;
_child = mapWidget();
});
}
#override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
Container(
alignment: Alignment.topCenter,
child: Padding(
padding: const EdgeInsets.only(top: 10, left: 50.0),
child: Column(
children: [
SizedBox(
child: Row(
children: [
Text(
'Company Data',
style: TextStyle(
fontFamily: 'Arial',
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black,
height: 2,
),
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Container(
margin: EdgeInsets.only(top: 10),
height: 3.0,
width: 200.0,
color: Color(4293492024),
),
),
],
),
),
],
),
),
),
Column(
children: [
MaterialButton(
onPressed: () {},
color: Color(4293492024),
textColor: Colors.white,
child: Icon(
Icons.camera_alt,
size: 24,
),
padding: EdgeInsets.all(16),
shape: CircleBorder(),
),
Text(
"Add Logo",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: Colors.black,
),
),
],
),
SizedBox(
height: 20,
),
Column(
children: [
Text(
"Project Name",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Container(
width: 300,
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Color(4293492024), width: 3.0),
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
child: TextField(
decoration: InputDecoration(
hintText: 'Project Name',
border: InputBorder.none,
),
),
),
Text(
"Project Number",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Container(
width: 300,
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Color(4293492024), width: 3.0),
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
child: TextField(
decoration: InputDecoration(
hintText: 'Number of workers',
border: InputBorder.none,
),
),
),
],
),
Container(
height: 200,
width: 400,
child: GoogleMap(
mapType: MapType.normal,
markers: _createMarker(),
initialCameraPosition: CameraPosition(
target: LatLng(position.latitude, position.longitude),
zoom: 12.0,
),
onMapCreated: (GoogleMapController controller) {
_controller = controller;
},
),
),
ElevatedButton(
child: Text("Next"),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => AddNewBody()),
),
style: ElevatedButton.styleFrom(
primary: Color(4293492024),
onPrimary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
)
],
),
);
}
}
I have added all dependencies.
pubspec.yaml file
dependencies:
google_maps_flutter: 0.5.30
geolocator: 5.1.2
location: 3.0.2
url_launcher: 5.7.5
flappy_search_bar: 1.4.1

How to use Flutter AnimatedContainer with height matching child

Currently this code works to resize a container to toggle between different content, but it's not animating. I think that I need to provide a height property to make the animation work, and when I do provide a height to toggle between it does match, like this:
height: selected ? 400 : 100,
The container animates smoothly between the two states. However the height is no longer adaptive. So I try to supply a height using:
GlobalKey _key = GlobalKey();
_size = _key.currentContext.size;
height: _size.height,
But it gives me errors and I'm not sure how to fix it.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool selected = false;
// GlobalKey _key = GlobalKey();
// Size _size = _key.currentContext.size;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
children: [
GestureDetector(
onTap: () {
setState(() {
selected = !selected;
// _size = _key.currentContext.size;
});
},
child: Padding(
padding: EdgeInsets.all(5),
child: AnimatedContainer(
// height: _size.height,
// key: _key,
duration: Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
if (selected)
Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
border: Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height:20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue, width: 1, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Text(
"Reply",
),
),
),
],
)
],
),
),
],
),
),
),
),
),
],
),
),
],
)
);
}
}
I thing AnimatedContainer is not Appropriate for this situation. I think its better to use AnimatedCrossFade. The AnimatedContainer will automatically animate between the old and new values of properties when they change using the provided curve and duration.
following code is refactored for using AnimatedCrossFade:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool selected = false;
// GlobalKey _key = GlobalKey();
// Size _size = _key.currentContext.size;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
children: [
GestureDetector(
onTap: () {
setState(() {
selected = !selected;
// _size = _key.currentContext.size;
});
},
child: Padding(
padding: EdgeInsets.all(5),
child: AnimatedCrossFade(
duration: Duration(seconds: 1),
crossFadeState: selected
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: Container(
// height: !selected ? 100 : 400,
// key: _key,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
if (selected)
Container(
child: Column(
children: [
Padding(
padding:
EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin:
EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(20.0),
color: Colors.white,
border:
Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding:
const EdgeInsets.all(
10.0)),
keyboardType:
TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding:
const EdgeInsets.all(10.0)),
keyboardType:
TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height: 20),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue,
width: 1,
style: BorderStyle.solid),
borderRadius:
BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(
0, 10, 0, 10),
child: Text(
"Reply",
),
),
),
],
)
],
),
),
],
),
),
),
secondChild: Container(
// height: !selected ? 100 : 400,
// key: _key,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
],
),
),
),
),
),
),
],
),
),
],
));
}
}
You can use custom animation to do this, like this:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
bool selected = false;
GlobalKey _key1 = GlobalKey();
GlobalKey _key2 = GlobalKey();
AnimationController _controller;
Animation _animation;
bool foward = false;
#override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: Duration(seconds: 1));
}
#override
void dispose() {
_controller.dispose();
super.dispose();
}
#override
void didChangeDependencies() {
super.didChangeDependencies();
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
_animation = Tween<double>(
begin: _key1.currentContext.size.height,
end: _key2.currentContext.size.height +
_key1.currentContext.size.height)
.chain(CurveTween(curve: Curves.fastOutSlowIn))
.animate(_controller);
});
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ListView(
children: [
Padding(
padding: EdgeInsets.all(5),
child: GestureDetector(
onTap: () {
if (foward) {
_controller.reverse();
} else {
_controller.forward();
}
foward = !foward;
},
child: (_animation == null)
? _buildWidget(_key1, _key2)
: AnimatedBuilder(
// curve: Curves.fastOutSlowIn,
animation: _controller,
builder: (context, child) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 2.5,
spreadRadius: 0.4,
color: Colors.grey,
offset: Offset(0, 0.5),
),
],
),
child: Padding(
padding: EdgeInsets.all(17.0),
child: Container(
height: _animation.value, child: child),
));
},
child: _buildWidget(_key1, _key2)),
),
),
],
)));
}
Widget _buildWidget(Key key1, Key key2) {
return SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Widget1(
key: _key1,
),
Widget2(
key: _key2,
),
],
),
);
}
}
class Widget1 extends StatefulWidget {
Widget1({Key key}) : super(key: key);
#override
_Widget1State createState() => _Widget1State();
}
class _Widget1State extends State<Widget1> {
#override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Text(
'Move fridge up stairs',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 5),
Text(
'Sarah - 2 days ago - 2.3km',
style: TextStyle(color: Colors.black54),
),
]);
}
}
class Widget2 extends StatefulWidget {
Widget2({Key key}) : super(key: key);
#override
Widget2State createState() => Widget2State();
}
class Widget2State extends State<Widget2> {
#override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Container(
child: Column(children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Text(
'Fridge is a single door. Sitting in kitchen. Need one strong person as I will help move it.',
style: TextStyle(
color: Colors.black54,
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.calendar_today,
color: Colors.black54,
size: 20,
),
Text(
' In three days',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Icon(
Icons.attach_money,
color: Colors.black54,
),
Text(
' 30',
style: TextStyle(
color: Colors.black54,
),
),
],
),
),
Row(
children: [
Text('Price : '),
Container(
width: 140,
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
border: Border.all(color: Colors.white),
),
child: Container(
child: TextField(
decoration: new InputDecoration(
hintText: "Your price",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.number,
maxLines: null,
),
),
),
],
),
Row(
children: [
Text('Reply : '),
Expanded(
child: TextField(
decoration: new InputDecoration(
hintText: "Enter your reply",
contentPadding: const EdgeInsets.all(10.0)),
keyboardType: TextInputType.multiline,
maxLines: null,
),
),
],
),
SizedBox(height: 20),
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
SizedBox(
width: 10,
),
FlatButton(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.blue, width: 1, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(50),
),
color: Colors.white,
textColor: Colors.black,
onPressed: () {
/*...*/
},
child: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Text(
"Reply",
),
))
])
]))
]);
}
}

How to make custom tabbar with gradient

How to make tab bar like below image in flutter?Is it possible to develop a Tabbar like below ?If not possible then what is the next better working solution?
Thank you for the support and i solved this issue my self without using any answers from stackoverflow
Try this way
I have created tab layout using ScrollablePositionedList
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widgets/flutter_widgets.dart';
void main() => runApp(HomeScreen());
int currentTab = 0;
class HomeScreen extends StatefulWidget {
#override
_HomeScreenPage createState() => _HomeScreenPage();
}
class TabModel {
String text;
TabModel({this.text});
}
List<TabModel> _tabList = [
TabModel(text: "Android"),
TabModel(text: "IOS"),
TabModel(text: "Java"),
TabModel(text: "JavaScript"),
TabModel(text: "PHP"),
TabModel(text: "HTML"),
TabModel(text: "C++"),
];
class _HomeScreenPage extends State<HomeScreen>
with SingleTickerProviderStateMixin {
PageController _controller = PageController(initialPage: 0, keepPage: false);
final ItemScrollController itemScrollController = ItemScrollController();
final ItemPositionsListener itemPositionListener =
ItemPositionsListener.create();
#override
void initState() {
super.initState();
}
#override
void dispose() {
super.dispose();
}
#override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.purple,
brightness: Brightness.light,
accentColor: Colors.red),
darkTheme: ThemeData(
brightness: Brightness.dark,
),
home: Scaffold(
appBar: AppBar(
title: Text("Custom TabBar"),
),
body: Column(
children: <Widget>[
Container(
height: 60,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14.0),
border: Border.all(color: Colors.black, width: 1.0)),
child: ScrollablePositionedList.builder(
scrollDirection: Axis.horizontal,
itemCount: _tabList.length,
itemBuilder: (context, index) {
return Container(
decoration: BoxDecoration(
gradient: currentTab == index
? LinearGradient(
colors: [
Colors.redAccent,
Colors.redAccent[200],
Colors.redAccent[100]
],
)
: null,
borderRadius: BorderRadius.circular(13.0),
),
child: FlatButton(
color: Colors.transparent,
onPressed: () {
setState(() {
currentTab = index;
_controller.jumpToPage(currentTab);
});
},
child: Text(
_tabList[index].text,
),
),
);
},
itemScrollController: itemScrollController,
itemPositionsListener: itemPositionListener,
)),
Flexible(
child: Container(
child: PageView(
controller: _controller,
onPageChanged: (pageId) {
setState(() {
currentTab = pageId;
itemScrollController.scrollTo(
index: currentTab, duration: Duration(seconds: 1));
});
},
children: <Widget>[
Container(
color: Colors.pink,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.cyan,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.red,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.green,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.grey,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.purple,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
Container(
color: Colors.teal,
child: Center(
child: Text(
_tabList[currentTab].text,
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontWeight: FontWeight.bold),
),
),
),
],
),
)),
],
)));
}
}
You can find source code for this demo from my github account
OUTPUT
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(home: MainScreen()),
);
class MainScreen extends StatefulWidget {
_MainState createState() => _MainState();
}
class _MainState extends State<MainScreen> {
int viewChoice = 0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Toolbar Title',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold /*fontSize,etc*/),
),
actions: [
IconButton(
icon: Icon(Icons.account_circle),
onPressed: () {
//Todo when pressed
}),
]),
body: Container(
child: Column(mainAxisSize: MainAxisSize.min, children: [
SizedBox(
height: 200,
width: double.infinity,
child: Stack(children: [
Container(
padding: EdgeInsets.all(10.0),
alignment: Alignment.centerLeft,
color: Colors.yellow,
height: 100.0,
width: double.infinity,
child: Text('Tem',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20.0)), //Tem is in your ex pic
),
Positioned(
top: 75.0,
left: 40.0,
right: 40.0,
child: Container(
margin: EdgeInsets.only(left: 25.0, right: 25.0),
alignment: Alignment.topCenter,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14.0),
border: Border.all(color: Colors.black, width: 1.0)),
child: Row(mainAxisSize: MainAxisSize.min, children: [
Expanded(
child: Container(
decoration: BoxDecoration(
gradient: viewChoice == 0
? LinearGradient(
colors: [Colors.orange, Colors.orangeAccent],
)
: null,
borderRadius: BorderRadius.circular(13.0),
border: viewChoice == 0
? Border.all(color: Colors.black, width: 1.0)
: null,
),
child: FlatButton(
color: Colors.transparent,
onPressed: () {
setState(() {
viewChoice = 0;
});
},
child: Text(
'All',
/*style as your requirement*/
),
),
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
gradient: viewChoice == 1
? LinearGradient(
colors: [Colors.orange, Colors.orangeAccent],
)
: null,
borderRadius: BorderRadius.circular(13.0),
border: viewChoice == 1
? Border.all(color: Colors.black, width: 1.0)
: null,
),
child: FlatButton(
onPressed: () {
setState(() {
viewChoice = 1;
});
},
child: Text(
'Favorites',
/*style as your requirement*/
),
),
),
),
]),
),
),
]),
),
viewChoice == 0
? ListView(shrinkWrap: true, children: [
//Content of All categories
])
: ListView(shrinkWrap: true, children: [
//Content of All categories
])
]),
),
);
}
}
TabBar without AppBar
Give a try to below code.
import 'package:flutter/material.dart';
import 'package:flutter_text_to_image/utils/app_colors.dart';
class TabBarWidget extends StatefulWidget {
final String firstTabTxt;
final String firstTabViewTxt;
final String secondTabTxt;
final String secondTabViewTxt;
const TabBarWidget({
super.key,
required this.firstTabTxt,
required this.secondTabTxt,
required this.firstTabViewTxt,
required this.secondTabViewTxt,
});
#override
State
<TabBarWidget>
createState() => _TabBarWidgetState();
}
class _TabBarWidgetState extends State
<TabBarWidget>
with SingleTickerProviderStateMixin {
TabController? _tabController;
#override
void initState() {
_tabController = TabController(length: 2, vsync: this);
super.initState();
}
#override
void dispose() {
_tabController?.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Container(
height: 100,
child: Column(
children: [
Container(
height: 35,
decoration: BoxDecoration(
border: Border.all(
color: AppColors.tabBorderColor,
),
borderRadius: BorderRadius.circular(
5.0,
),
),
child: TabBar(
controller: _tabController,
indicator: BoxDecoration(
gradient: LinearGradient(
colors: [
AppColors.waterMelonColor,
AppColors.mangoColor,
AppColors.azureColor,
AppColors.sapphireColor,
],
begin: FractionalOffset(0.0, 0.0),
end: FractionalOffset(1.0, 0.0),
stops: [
0.1,
0.4,
0.6,
1.0,
],
tileMode: TileMode.clamp,
),
borderRadius: BorderRadius.circular(
2.0,
),
),
labelColor: AppColors.whiteColor,
unselectedLabelColor: AppColors.blackColor,
tabs: [
Tab(
text: widget.firstTabTxt,
),
Tab(
text: widget.secondTabTxt,
),
],
),
),
Expanded(
child: TabBarView(
controller: _tabController,
children: [
Padding(
padding: EdgeInsets.only(top: 10),
child: Column(
children: [
Text(
widget.firstTabViewTxt,
),
],
),
),
Padding(
padding: EdgeInsets.only(top: 10),
child: Column(
children: [
Text(
widget.secondTabViewTxt,
),
],
),
),
],
),
),
],
),
);
}
}