I am getting two appBar in flutter app. I am trying to add Drawer widget and TabBar widget in flutter app - flutter

main.dart
import 'package:flutter/material.dart';
import 'package:stray_animal_emergencyrescue/signUpPage.dart';
import './commons/commonWidgets.dart';
import 'package:stray_animal_emergencyrescue/loggedIn.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 login UI',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
//String showPasswordText = "Show Password";
bool obscurePasswordText = true;
#override
Widget build(BuildContext context) {
final passwordField = TextField(
obscureText: obscurePasswordText,
decoration: InputDecoration(
//contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Password",
//border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0)),
suffixIcon: IconButton(
icon: new Icon(Icons.remove_red_eye),
onPressed: () {
setState(() {
this.obscurePasswordText = !obscurePasswordText;
});
},
)),
);
final loginButon = Material(
//elevation: 5.0,
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
//print(MediaQuery.of(context).size.width);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LogIn()),
);
},
child: Text('Login', textAlign: TextAlign.center),
),
);
final facebookContinueButton = Material(
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
//print(MediaQuery.of(context).size.width);
},
child: Text('Facebook', textAlign: TextAlign.center),
),
);
final googleContinueButton = Material(
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
//print(MediaQuery.of(context).size.width);
},
child: Text('Google ', textAlign: TextAlign.center),
),
);
final signUpButton = Material(
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => FormScreen()),
);
//print(MediaQuery.of(context).size.width);
},
child: Text('Sign Up ', textAlign: TextAlign.center),
),
);
return Scaffold(
appBar: AppBar(
title: Text("Animal Emergency App"),
),
body: Center(
child: Container(
//color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(36.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//SizedBox(height: 45.0),
getTextFieldWidget(),
SizedBox(height: 15.0),
passwordField,
sizedBoxWidget,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
facebookContinueButton,
SizedBox(width: 5),
googleContinueButton,
SizedBox(width: 5),
loginButon
],
),
/*loginButon,
signUpButton,*/
sizedBoxWidget,
const Divider(
color: Colors.black,
height: 20,
thickness: 1,
indent: 20,
endIndent: 0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
signUpButton
],
),
],
),
),
),
),
);
}
}
loggedIn.dart
import 'package:flutter/material.dart';
import './tabbarviews/emergencyresue/EmergencyHome.dart';
import './tabbarviews/animalcruelty/animalCrueltyHome.dart';
import './tabbarviews/bloodbank/bloodBankHome.dart';
class LogIn extends StatefulWidget {
#override
_LogInState createState() => _LogInState();
}
class _LogInState extends State<LogIn> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static List<Widget> _widgetOptions = <Widget>[
EmergencyHome(),
AnimalCrueltyHome(),
BloodBankHome()
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First app bar appearing'),
actions: <Widget>[
GestureDetector(
onTap: () {},
child: CircleAvatar(
//child: Text("SC"),
backgroundImage: AssetImage('assets/images/760279.jpg'),
//backgroundImage: ,
),
),
IconButton(
icon: Icon(Icons.more_vert),
color: Colors.white,
onPressed: () {},
),
],
),
drawer: Drawer(
child: ListView(
children: <Widget>[
new ListTile(title: Text("Primary")),
MyListTile(
"Home",
false,
"Your customized News Feed about people you follow, ongoing rescues, nearby activities, adoptions etc.",
3,
Icons.home,
true,
() {}),
MyListTile(
"News & Media Coverage",
false,
"News about incidents which need immediate action, changing Laws",
3,
Icons.home,
false,
() {}),
MyListTile(
"Report",
true,
"Report cases with evidences anonymously",
3,
Icons.announcement,
false,
() {}),
MyListTile(
"Blood Bank",
true,
"Details to donate blood ",
3,
Icons.medical_services,
false,
() {}),
],
),
),
body: _widgetOptions[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
selectedItemColor: Colors.blue,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.pets),
label: 'Emergency Rescue',
),
BottomNavigationBarItem(
icon: Icon(Icons.add_alert),
label: 'Report Cruelty',
),
BottomNavigationBarItem(
icon: Icon(Icons.medical_services),
label: 'Blood Bank',
),
/*BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Safe Hands',
backgroundColor: Colors.blue),*/
],
onTap: _onItemTapped,
),
);
}
}
//Safe Hands
class MyListTile extends StatelessWidget {
final String title;
final bool isThreeLine;
final String subtitle;
final int maxLines;
final IconData icon;
final bool selected;
final Function onTap;
MyListTile(this.title, this.isThreeLine, this.subtitle, this.maxLines,
this.icon, this.selected, this.onTap);
#override
Widget build(BuildContext context) {
return ListTile(
title: Text(title),
isThreeLine: isThreeLine,
subtitle:
Text(subtitle, maxLines: maxLines, style: TextStyle(fontSize: 12)),
leading: Icon(icon),
selected: selected,
onTap: onTap);
}
}
EmergencyHome.dart
import 'package:flutter/material.dart';
import './finishedAnimalEmergencies.dart';
import './reportAnimalEmergency.dart';
import './ongoingAnimalEmergencies.dart';
class EmergencyHome extends StatefulWidget {
#override
_EmergencyHomeState createState() => _EmergencyHomeState();
}
class _EmergencyHomeState extends State<EmergencyHome> {
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text("Second appBar appearing"),
bottom: TabBar(
tabs: [
Tab(
//icon: Icon(Icons.more_vert),
text: "Report",
),
Tab(
text: "Ongoing",
),
Tab(
text: "Finished",
)
],
),
),
body: TabBarView(
children: [
ReportAnimalEmergency(),
OngoingAnimalEmergencies(),
FinishedAnimalEmergencies(),
],
),
)
);
}
}
The issue I am facing is two appBar, I tried removing appBar from loggedIn.dart but Drawer hamburger icon is not showing, and I cannot remove appBar from emergencyHome.dart as I wont be able to add Tab bar. What is viable solution for this? Please help how to Structure by app and routes to easily manage navigation within app

Remove the appbar from EmergencyHome.dart
this will remove the second app title. But there will be that shadow from the first app bar so put elvation:0
so, this will look like one appbar now your drawer will also work.

you can use flexibleSpace in EmergencyHome.dart
DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
flexibleSpace: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TabBar(
tabs: [
Tab(
//icon: Icon(Icons.more_vert),
text: "Report",
),
Tab(
text: "Ongoing",
),
Tab(
text: "Finished",
)
],
)
],
),
),
body: TabBarView(
children: [
ReportAnimalEmergency(),
OngoingAnimalEmergencies(),
FinishedAnimalEmergencies(),
],
),
)
);

You don't want to make two appbar to get the drawer property. Use DefaultTabController then inside that you can use scaffold.so, you can have drawer: Drawer() inside that you can also get a appbar with it with TabBar as it's bottom.
This is most suitable for you according to your use case.
i will put the full code below so you can copy it.
void main() {
runApp(const TabBarDemo());
}
class TabBarDemo extends StatelessWidget {
const TabBarDemo({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
drawer: Drawer(),
appBar: AppBar(
bottom: const TabBar(
tabs: [
Tab(
text: "report",
),
Tab(text: "ongoing"),
Tab(text: "completed"),
],
),
title: const Text('Tabs Demo'),
),
body: const TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
),
);
}
}
OUTPUT

Related

Problem in multilingualizing the app in flutter

I encountered a problem in making my app multilingual.
On the other pages of my app, when the code
S.of(context).myText is called, the code works correctly and And the text corresponding to the language chosen by the audience is displayed, but on the one class of my app named Home, by calling this program code, regardless of the selected language, only the English text is displayed shows even if I choose Malaysia or Arabic.
Interestingly, when I build the project with Chrome, there is no problem, but when I download the apk from it, it does not work on the mobile.
the problem is with S.of(context).Home_drawer_mainMenu, in below code:
my Home class:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:untitled22/SignUp.dart';
import 'package:untitled22/TabBarViewHome.dart';
import 'package:untitled22/loginFile.dart';
import './Page_1.dart';
import './Page_2.dart';
import './Page_3.dart';
import './Page_4.dart';
import 'LanguageChangeProvider.dart';
import 'package:untitled22/generated/l10n.dart';
void main() {
runApp(const MaterialApp(
home: HomePage(),
debugShowCheckedModeBanner: false,
));
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int pageNumb = 0;
late TabController _controller;
String _currentLanguage = 'ar';
bool rtl = false;
#override
void initState() {
_loadCounter();
super.initState();
}
_loadCounter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
_currentLanguage = (prefs.getString('currentLang') ?? '');
rtl = (prefs.getBool('isRtl') ?? false);
});
}
#override
Widget build(BuildContext context) {
return MaterialApp(
locale: new Locale(_currentLanguage),
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
home: BodyBody(),
debugShowCheckedModeBanner: false,
showSemanticsDebugger: false,
);
}
}
class BodyBody extends StatefulWidget {
const BodyBody({Key? key}) : super(key: key);
#override
State<BodyBody> createState() => _BodyBodyState();
}
class _BodyBodyState extends State<BodyBody> with SingleTickerProviderStateMixin {
int pageNumb = 0;
late TabController _controller;
String _currentLanguage = '';
bool rtl = false;
#override
void initState() {
_loadCounter();
super.initState();
_controller = TabController(vsync: this, length: 3, initialIndex: 1);
}
_loadCounter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
_currentLanguage = (prefs.getString('currentLang') ?? 'ar');
rtl = (prefs.getBool('isRtl') ?? false);
});
}
#override
Widget build(BuildContext context) {
Size media = MediaQuery.of(context).size;
var height = AppBar().preferredSize.height;
TextEditingController textController = TextEditingController();
return DefaultTabController(
initialIndex: 1,
length: 3,
child: Scaffold(
appBar: AppBar(
titleSpacing: 0,
title: Text(
S.of(context).Home_drawer_mainMenu,
style: TextStyle(
color: Color(0xFF434343),
fontSize: rtl == true ? 16 : 14,
),
),
backgroundColor: const Color(0xff26c6da),
leading: Builder(
builder: (BuildContext context) {
return Container(
child: IconButton(
icon: const Icon(Icons.menu),
onPressed: () {
Scaffold.of(context).openDrawer();
},
color: const Color(0xFF434343),
),
);
},
),
actions: <Widget>[
IconButton(
onPressed: () {
print(height);
},
icon: Icon(Icons.search),
padding: rtl == false ? const EdgeInsets.only(right: 10) : const EdgeInsets.only(left: 10),
color: const Color(0xFF434343),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.settings),
padding: rtl == false ? const EdgeInsets.only(right: 15) : const EdgeInsets.only(left: 15),
color: const Color(0xFF434343),
),
],
bottom: TabBar(
controller: _controller,
labelColor: Color(0xff434343),
unselectedLabelColor: Color(0xff434343),
indicatorColor: Color(0xff434343),
automaticIndicatorColorAdjustment: false,
tabs: <Widget>[
Tab(
icon: Icon(Icons.event_note_outlined),
),
Tab(
icon: Icon(Icons.home_rounded),
),
Tab(
icon: Icon(Icons.add_alert),
),
],
),
),
body: TabBarView(
controller: _controller,
children: [
TabBarHome(width: media.width, height: media.height),
TabBarHome(width: media.width, height: media.height),
TabBarHome(width: media.width, height: media.height),
],
),
drawer: Drawer(
child: ListView(
children: [
GestureDetector(
onTap: () {
print('hey');
},
child: InkWell(
onTap: () {},
child: Container(
color: Colors.grey.shade100,
height: media.height * 0.2,
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
height: 70,
width: 90,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fitWidth,
image: AssetImage("images/aga.png"),
)),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
"Text",
style: TextStyle(
fontSize: 17,
color: Colors.black87,
fontWeight: FontWeight.w600,
),
),
Text(
"The best leader",
textAlign: TextAlign.justify,
style: TextStyle(
fontSize: 15,
color: Colors.black87,
),
),
],
),
],
),
Container(
child: rtl == true ? Icon(Icons.keyboard_arrow_right_rounded) : Icon(Icons.keyboard_arrow_left_rounded),
),
],
),
),
),
),
),
),
Padding(
padding: EdgeInsets.all(10),
child: Text(
S.of(context).Home_drawer_mainMenu,
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
),
),
ListTile(
leading: Icon(Icons.home),
title: Text('data'),
),
ListTile(
leading: Icon(Icons.add_call),
title: Text('call with us'),
),
],
),
),
),
);
}
}

It is not accepted to change the value in the Dropdown in the bottom sheet?

Flutter . It is not accepted to change the value in the Dropdown in the bottom sheet ?
I made all the changes and it didn't work !
Knowing that on a normal screen it works
please help me
class _AddPostState extends State<AddPost> {
List<DropdownMenuItem<String>> get itemse{
List<DropdownMenuItem<String>> menuItems = [
DropdownMenuItem(
value: '1',
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
SizedBox(width: 15,),
Icon(Icons.lock_outline,size: 19,),
SizedBox(width: 10,),
Text('Only me'),
],
),
),
),
DropdownMenuItem(
value: '2',
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
SizedBox(width: 15,),
Icon(Icons.group_rounded,size: 19,),
SizedBox(width: 10,),
Text('Friends'),
],
),
),
),
DropdownMenuItem(
value: '3',
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
SizedBox(width: 15,),
Icon(Icons.public,size: 19,),
SizedBox(width: 10,),
Text('Public'),
],
),
),
),
];
return menuItems;
}
String? selectedValue = '1';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
foregroundColor: Colors.black,
backgroundColor: Colors.white,
title: const Text('Add Post'),
),
body: Center(
child: ElevatedButton(
child: const Text('Open'),
onPressed: bottomSheet,
),
),
);
}
void bottomSheet(){
showCupertinoModalBottomSheet(
expand: true,
context: context,
backgroundColor: Colors.transparent,
builder: (context) =>Scaffold(
appBar: AppBar(backgroundColor: Colors.white,foregroundColor: Colors.black,),
body: Column(
children: [
DropdownButton(
value: selectedValue,
items: itemse,
onChanged: (y) {
setState(() {
selectedValue = y! as String;
});
},
)
],
),
),
);
}
}
Seven days, I searched for a solution to the problem and did not find the solution. Please help
From the code i see you are not using the StatefulBuilder which will rebuild the sheet and change your value. From the code that you provided i have just created and example for you which might help you.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<DropdownMenuItem<String>> get itemse {
List<DropdownMenuItem<String>> menuItems = [
DropdownMenuItem(
value: '1',
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
SizedBox(
width: 15,
),
Icon(
Icons.lock_outline,
size: 19,
),
SizedBox(
width: 10,
),
Text('Only me'),
],
),
),
),
DropdownMenuItem(
value: '2',
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
SizedBox(
width: 15,
),
Icon(
Icons.group_rounded,
size: 19,
),
SizedBox(
width: 10,
),
Text('Friends'),
],
),
),
),
DropdownMenuItem(
value: '3',
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
SizedBox(
width: 15,
),
Icon(
Icons.public,
size: 19,
),
SizedBox(
width: 10,
),
Text('Public'),
],
),
),
),
];
return menuItems;
}
String? selectedValue = '1';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
foregroundColor: Colors.black,
backgroundColor: Colors.white,
title: const Text('Add Post'),
),
body: Center(
child: ElevatedButton(
child: const Text('Open'),
onPressed: bottomSheet,
),
),
);
}
void bottomSheet() {
showCupertinoModalBottomSheet(
expand: true,
context: context,
backgroundColor: Colors.transparent,
builder: (context) =>
StatefulBuilder(builder: (BuildContext context, StateSetter setState /*You can rename this!*/) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
),
body: Column(
children: [
DropdownButton(
value: selectedValue,
items: itemse,
onChanged: (y) {
setState(() {
selectedValue = y! as String;
});
},
)
],
),
);
}),
);
}
}

Is there any way to put custom toolbar on the keypad?

I want to put a custom toolbar on the keypad like the image above. Is it possible in flutter? or should I write code on the iOS or Android side?
You can copy paste run full code below
Please see working demo below
You can use package https://pub.dev/packages/keyboard_overlay
Step 1: Use with HandleFocusNodesOverlayMixin
Step 2: Use FocusNodeOverlay for focusNode
Step 3: Use GetFocusNodeOverlay and set _focusNodeOverlay = GetFocusNodeOverlay(
Step 4: TextField use TextField(focusNode: _focusNodeOverlay,
code snippet
class _MyHomePageState extends State<MyHomePage>
with HandleFocusNodesOverlayMixin {
FocusNodeOverlay _focusNodeOverlay;
#override
void initState() {
_focusNodeOverlay = GetFocusNodeOverlay(
child: TopKeyboardUtil(
Container(
color: Colors.white,
height: 45,
width: MediaQueryData.fromWindow(ui.window).size.width,
child: Row(
children: [
GestureDetector(
child: Icon(Icons.save),
onTap: () => print("click"),
),
...
Spacer(),
Container(
width: 60,
child: Center(
child: DoneButtonIos(
backgroundColor: Colors.white,
textColor: Colors.green,
label: 'Post',
onSubmitted: () {
print("submit");
},
platforms: ['android', 'ios'],
),
),
),
],
),
),
),
);
working demo
full code
import 'package:flutter/material.dart';
import 'package:keyboard_overlay/keyboard_overlay.dart';
import 'dart:ui' as ui;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with HandleFocusNodesOverlayMixin {
FocusNodeOverlay _focusNodeOverlay;
#override
void initState() {
_focusNodeOverlay = GetFocusNodeOverlay(
child: TopKeyboardUtil(
Container(
color: Colors.white,
height: 45,
width: MediaQueryData.fromWindow(ui.window).size.width,
child: Row(
children: [
GestureDetector(
child: Icon(Icons.save),
onTap: () => print("click"),
),
GestureDetector(
child: Icon(Icons.computer),
onTap: () => print("click"),
),
GestureDetector(
child: Icon(Icons.home),
onTap: () => print("click"),
),
Spacer(),
Container(
width: 60,
child: Center(
child: DoneButtonIos(
backgroundColor: Colors.white,
textColor: Colors.green,
label: 'Post',
onSubmitted: () {
print("submit");
},
platforms: ['android', 'ios'],
),
),
),
],
),
),
),
);
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
focusNode: _focusNodeOverlay,
style: TextStyle(color: Colors.grey),
decoration: InputDecoration(
labelText: 'Type Something',
labelStyle: TextStyle(color: Colors.black),
fillColor: Colors.orange,
hintStyle: TextStyle(
color: Colors.grey,
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.black, width: 1.0),
),
),
),
],
),
),
);
}
}
Yes there is a way around in the flutter to achieve this.
Create a widget of the toolbar you want to add.
Set it visible on input focus.
For reference I am sharing the code how I achieve that.
class InputDoneView extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
color: Style.lightGrey,
child: Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.only(top: 1.0, bottom: 1.0),
child: CupertinoButton(
padding: EdgeInsets.only(right: 24.0, top: 2.0, bottom: 2.0),
onPressed: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: Text(
"Done",
style: TextStyle(color: Style.primaryColor,fontWeight: FontWeight.normal)
),
),
),
),
);
}
}
To call this in your main view when input field is focused in and out.
showOverlay(BuildContext context) {
if (overlayEntry != null) return;
OverlayState overlayState = Overlay.of(context);
overlayEntry = OverlayEntry(builder: (context) {
return Positioned(
bottom: MediaQuery.of(context).viewInsets.bottom, right: 0.0, left: 0.0, child: InputDoneView());
});
overlayState.insert(overlayEntry);
}
removeOverlay() {
if (overlayEntry != null) {
overlayEntry.remove();
overlayEntry = null;
}
}

How to use itemBuilder to select the last tapped ListTile widget?

I am trying to change the selected property of the last tapped ListTile widget to true inside a Drawer (and then obviously the selected property of other ListTiles to false), but I do not understand how can I use itemBuilder (which is mentioned in the official flutter docs) for this.
I tried putting my ListTiles into an AnimatedListItemBuilder widget, but that was not working for me.
Widget _buildDrawer() {
return ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child:
Wrap(
alignment: WrapAlignment.center,
direction: Axis.vertical,
children: <Widget>[
Text(
_currentUser.displayName,
style: TextStyle(
fontSize: 20,
color: Colors.white
),
),
Wrap(
direction: Axis.vertical,
children: <Widget>[
Text(
"Iskolai kategória: A",
style: TextStyle(
fontSize: 18,
color: Colors.white70
),
),
Text(
"Kollégiumi kategória: A",
style: TextStyle(
fontSize: 18,
color: Colors.white70
),
),
],
)
],
),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
selected: true,
leading: Icon(Icons.date_range_rounded),
title: Text('Stúdium jelentkezés'),
onTap: () {
// Update the state of the app.
// ...
// Then close the drawer.
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.article_rounded),
title: Text('Koleszhírek'),
onTap: () {
// Update the state of the app.
// ...
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.account_box_rounded),
title: Text('Profil'),
onTap: () {
// Update the state of the app.
// ...
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.logout),
title: Text('Kijelentkezés'),
onTap: () => {
_googleSignIn.disconnect(),
Navigator.pop(context)
},
),
],
);
}
You have to save the 'selected index' in a variable and check if the current index equals selected index to highlight the ListView. I've updated your code to make it work.
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,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
drawer: _buildDrawer(context),
body: Center(
child: Text("DrawerHeader Demo"),
),
);
}
Widget _buildDrawer(BuildContext context) {
List<Widget> leading = [
Icon(Icons.date_range_rounded),
Icon(Icons.article_rounded),
Icon(Icons.account_box_rounded),
Icon(Icons.logout),
];
List<Widget> title = [
Text('Stúdium jelentkezés'),
Text('Koleszhírek'),
Text('Profil'),
Text('Kijelentkezés'),
];
return Container(
color: Colors.white,
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Wrap(
alignment: WrapAlignment.center,
direction: Axis.vertical,
children: <Widget>[
Text(
"A",
style: TextStyle(fontSize: 20, color: Colors.white),
),
Wrap(
direction: Axis.vertical,
children: <Widget>[
Text(
"Iskolai kategória: A",
style: TextStyle(fontSize: 18, color: Colors.white70),
),
Text(
"Kollégiumi kategória: A",
style: TextStyle(fontSize: 18, color: Colors.white70),
),
],
)
],
),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListView.builder(
itemCount: 4,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: title[index],
leading: leading[index],
selected: index == _selectedIndex,
onTap: () {
setState(() {
_selectedIndex = index;
Navigator.pop(context);
});
},
);
},
),
],
),
);
}
}

Layout issue: TabBarView with TextField Keyboard overflow

I'm trying to implement a specific design and as thhe title says I have encountered an issue in building my layout.
When I'm taping inside my TextField the keyboard open itself and create an overflow.
Screenshots
Code
deals_edition_page.dart
import 'package:flutter/material.dart';
import 'package:myuca/ui/manager/deals/edition_informations_tab.dart';
class DealsEditionPage extends StatefulWidget {
#override
State<StatefulWidget> createState() => _DealsEditionPageState();
}
class _DealsEditionPageState extends State<DealsEditionPage> {
MemoryImage _image;
Widget _buildAppbar() {
return AppBar(
elevation: 0,
leading: IconButton(
icon: Icon(Icons.close),
onPressed: () => Navigator.pop(context),
),
title: Text(/* random String */),
actions: [
IconButton(
icon: Icon(Icons.check),
onPressed: () => Navigator.pop(context),
),
],
);
}
Widget _buildHeaderTabBar() {
return SliverAppBar(
automaticallyImplyLeading: false,
expandedHeight: 224,
floating: true,
elevation: 0,
flexibleSpace:
FlexibleSpaceBar(background: Image.memory(_image.bytes, fit: BoxFit.cover)),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: _buildAppbar(),
body: DefaultTabController(
length: 2,
child: CustomScrollView(
slivers: <Widget>[
_buildHeaderTabBar(),
SliverToBoxAdapter(
child: TabBar(
indicatorWeight: 2,
tabs: [
Tab(text: 'Informations'),
Tab(text: 'Informations'),
],
),
),
SliverFillRemaining(
child: Column(
children: [
Expanded(
child: TabBarView(
children: [
EditionInformationsTab(),
Center(child: Text("Tab 2")),
],
),
),
],
),
),
],
),
),
);
}
}
edition_informations_tab.dart
import 'package:flutter/material.dart';
import 'package:myuca/extensions/extensions.dart' show WidgetModifier;
class EditionInformationsTab extends StatefulWidget {
#override
State<StatefulWidget> createState() => _EditionInformationsTabState();
}
class _EditionInformationsTabState extends State<EditionInformationsTab> {
final _list1 = <String>['Culture', 'Test'];
final _list2 = <String>['Etablissement', 'Test 1', 'Test 2'];
List<DropdownMenuItem<String>> _menuItemsGenerator(List<String> values) =>
values
.map<DropdownMenuItem<String>>((e) => DropdownMenuItem<String>(
value: e,
child: Text(e),
))
.toList();
#override
Widget build(BuildContext context) {
return Form(
child: Column(
children: [
DropdownButtonFormField<String>(
value: _list1.first,
decoration: InputDecoration(
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(4))),
items: _menuItemsGenerator(_list1),
onChanged: (_) {},
).padding(EdgeInsets.only(bottom: 24)),
DropdownButtonFormField(
value: _list2.first,
decoration: InputDecoration(
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(4))),
items: _menuItemsGenerator(_list2),
onChanged: (_) {},
).padding(EdgeInsets.only(bottom: 24)),
TextFormField(
maxLength: 30,
decoration: InputDecoration(
labelText: "Nom de l'offre",
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(4))),
),
],
),
).padding(EdgeInsets.only(
top: 16, left: 16, right: 16));
}
}
Any idea on how I could avoid this overflow when the keyboard is displayed ?
You can copy paste run full code below
You can in _EditionInformationsTabState wrap with SingleChildScrollView
class _EditionInformationsTabState extends State<EditionInformationsTab> {
...
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
working demo
full code
import 'package:flutter/material.dart';
class DealsEditionPage extends StatefulWidget {
#override
State<StatefulWidget> createState() => _DealsEditionPageState();
}
class _DealsEditionPageState extends State<DealsEditionPage> {
MemoryImage _image;
Widget _buildAppbar() {
return AppBar(
elevation: 0,
leading: IconButton(
icon: Icon(Icons.close),
onPressed: () => Navigator.pop(context),
),
title: Text("demo"),
actions: [
IconButton(
icon: Icon(Icons.check),
onPressed: () => Navigator.pop(context),
),
],
);
}
Widget _buildHeaderTabBar() {
return SliverAppBar(
automaticallyImplyLeading: false,
expandedHeight: 224,
floating: true,
elevation: 0,
flexibleSpace: FlexibleSpaceBar(
background: Image.network("https://picsum.photos/250?image=9",
fit: BoxFit.cover)),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: _buildAppbar(),
body: DefaultTabController(
length: 2,
child: CustomScrollView(
slivers: <Widget>[
_buildHeaderTabBar(),
SliverToBoxAdapter(
child: TabBar(
indicatorWeight: 2,
tabs: [
Tab(text: 'Informations'),
Tab(text: 'Informations'),
],
),
),
SliverFillRemaining(
child: Column(
children: [
Expanded(
child: TabBarView(
children: [
EditionInformationsTab(),
Center(child: Text("Tab 2")),
],
),
),
],
),
),
],
),
),
);
}
}
class EditionInformationsTab extends StatefulWidget {
#override
State<StatefulWidget> createState() => _EditionInformationsTabState();
}
class _EditionInformationsTabState extends State<EditionInformationsTab> {
final _list1 = <String>['Culture', 'Test'];
final _list2 = <String>['Etablissement', 'Test 1', 'Test 2'];
List<DropdownMenuItem<String>> _menuItemsGenerator(List<String> values) =>
values
.map<DropdownMenuItem<String>>((e) => DropdownMenuItem<String>(
value: e,
child: Text(e),
))
.toList();
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(top: 16, left: 16, right: 16),
child: Form(
child: Column(
children: [
Padding(
padding: EdgeInsets.only(bottom: 24),
child: DropdownButtonFormField<String>(
value: _list1.first,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4))),
items: _menuItemsGenerator(_list1),
onChanged: (_) {},
),
),
Padding(
padding: EdgeInsets.only(bottom: 24),
child: DropdownButtonFormField(
value: _list2.first,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4))),
items: _menuItemsGenerator(_list2),
onChanged: (_) {},
),
),
TextFormField(
maxLength: 30,
decoration: InputDecoration(
labelText: "Nom de l'offre",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4))),
),
],
),
),
),
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: DealsEditionPage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}