how to show all text (Flutter)? - flutter

how to show the text in full? I'm getting this error (on the screen).
what should I change in my code? Is there any way to do it? In case you want to see the code please let me know I will update more.
read_mode.dart
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:quiz2/const/state.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:quiz2/database/category_provider.dart';
import 'package:quiz2/database/db_helper.dart';
import 'package:quiz2/database/question_provider.dart';
import 'package:quiz2/model/user_answer_model.dart';
import 'package:quiz2/utils/utils.dart';
import 'package:quiz2/widgets/question_body.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ReadModePage extends StatefulWidget {
ReadModePage({Key key, this.title}):super(key: key);
final String title;
#override
_ReadModePageState createState() => _ReadModePageState();
}
class _ReadModePageState extends State<ReadModePage> {
SharedPreferences prefs;
int indexPage = 0;
CarouselController buttonCarouselController = CarouselController();
List<UserAnswer> userAnswers = new List<UserAnswer>();
#override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async{
prefs = await SharedPreferences.getInstance();
indexPage = await prefs.getInt("${context.read(questionCategoryState).state.name}_${context.read(questionCategoryState).state.ID}") ?? 0;
print('Save index page: ${indexPage}');
Future.delayed(Duration(milliseconds: 500)).then((value) => buttonCarouselController.animateToPage(indexPage));
});
}
#override
Widget build(BuildContext context) {
var questionModule = context.read(questionCategoryState).state;
return WillPopScope(child: Scaffold(
appBar: AppBar(title: Text(questionModule.name),
leading: GestureDetector(onTap: () => showCloseDialog(questionModule),
child: Icon(Icons.arrow_back), ),),
body: Container(
color: Colors.teal[100],
child: FutureBuilder<List<Question>>(
future: getQuestionByCategory(questionModule.ID),
builder: (context, snapshot){
if(snapshot.hasError)
return Center(
child: Text('${snapshot.error}'),);
else if(snapshot.hasData)
{
if(snapshot.data.length>0)
{
return Container(margin: const EdgeInsets.all(5.0),
alignment: Alignment.topCenter,
child: Card(
elevation: 20,
child: Container(
child: SingleChildScrollView(
child: Column(children: [
SizedBox(height: 15,),
QuestionBody(context: context,
carouselController: buttonCarouselController,
questions: snapshot.data,
userAnswers: userAnswers,),
SizedBox(height: 30,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(onPressed: () => showAnswer(context), child: Text("Show Answer"))
],)
],)
)
)
));
}
else return Center(
child: Text('Category don\'n have any question'));
} else
return Center(
child: CircularProgressIndicator(),);
}
),
),
), onWillPop: () async{
showCloseDialog(questionModule);
return true;
});
}
showCloseDialog(Category questionModule) {
showDialog(
context: context,
builder:(_) => new AlertDialog(
title: Text('Close'),
content: Text("Do you want to save this question index?"),
actions: [
TextButton(onPressed: (){
Navigator.of(context).pop(); //close dialog
Navigator.pop(context); //close screen
}, child: Text("No")),
TextButton(onPressed: (){
prefs.setInt("${context.read(questionCategoryState).state.name}_${context.read(questionCategoryState).state.ID}",
context.read(currentReadPage).state);
Navigator.of(context).pop(); //close dialog
Navigator.pop(context); //close screen
}, child: Text("Yes"))
],)
);
}
}
Future <List<Question>> getQuestionByCategory(int id) async{
var db = await copyDB();
var result = await QuestionProvider().getQuestionCategoryId(db, id);
return result;
}
question_body.dart
import 'package:auto_size_text/auto_size_text.dart';
import 'package:carousel_slider/carousel_controller.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:quiz2/const/state.dart';
import 'package:quiz2/database/question_provider.dart';
import 'package:quiz2/model/user_answer_model.dart';
import 'package:flutter/material.dart';
import 'package:quiz2/utils/utils.dart';
class QuestionBody extends StatelessWidget {
QuestionBody({Key key,
this.context,
this.userAnswers,
this.carouselController,
this.questions}):super(key:key);
BuildContext context;
List<UserAnswer> userAnswers;
CarouselController carouselController;
List<Question> questions;
#override
Widget build(BuildContext context){
return CarouselSlider(
carouselController: carouselController,
items: questions.asMap().entries.map((e) => Builder(
builder: (context) {
return Consumer(builder: (context, watch, _){
var userAnswerState = watch(userAnswerSelected).state;
var isShowAnswer = watch(isEnableShowAnswer).state;
return Column(
children: [
Expanded(
child: Column(
children: [
Text( //Question
context.read(isTestMode).state ? "${e.key+1}: ${e.value.questionText}":
"${e.value.questionId}: ${e.value.questionText}",
style: TextStyle(height:2, fontSize: 16)),
Visibility(//Question is image
visible: (e.value.isImageQuestion == null || e.value.isImageQuestion == 0 ? false:true),
child: Container(
height: MediaQuery.of(context).size.height/15*2,
child: e.value.isImageQuestion == 0 ? Container():
Image.network("${e.value.questionImage}",
fit: BoxFit.fill,)
)),
Expanded( //Answer A
child: ListTile(
title: AutoSizeText('${e.value.answerA}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'A' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "A",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
)),
Expanded( //Answer B
child: ListTile(
title: AutoSizeText('${e.value.answerB}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'B' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "B",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
)),
Expanded( //Answer C
child: ListTile(
title: AutoSizeText('${e.value.answerC}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'C' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "C",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
)),
Expanded( //Answer D
child: ListTile(
title: AutoSizeText('${e.value.answerD}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'D' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "D",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
))
],
)),
],
);
},
);
},
)).toList(), options: CarouselOptions(
autoPlay: false,
enlargeCenterPage: true,
viewportFraction: 0.9,
initialPage: 0,
height: MediaQuery.of(context).size.height/5*2,
onPageChanged: (page,_){
context.read(currentReadPage).state = page;
context.read(isEnableShowAnswer).state = false;
}
));
}
getGroupValue(bool isShowAnnswer, MapEntry<int, Question> e, UserAnswer userAnswerState){
return isShowAnnswer ? e.value.correctAnswer : (context.read(isTestMode).state ?
context.read(userListAnswer).state[e.key].answered:'');
}
}
Is there any way to do it? In case you want to see the code please let me know I will update more.
screen

Your widget tree seems a bit complicated for no reason.
Assuming what you wanted to achieve was to have your Show Answer button always be visible at the bottom of the Card and the other content on the top of this button to scroll itself inside the Card, this is a much better way to have the structure,
class Minimal extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Minimal')),
body: Container(
margin: const EdgeInsets.all(5.0),
alignment: Alignment.topCenter,
child: Card(
elevation: 20,
child: Container(
height: MediaQuery.of(context).size.height / 5 * 2,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(height: 15),
Container(
color: Colors.deepOrange,
width: double.infinity,
child: Column(
children: [
// Replace this Text with your QuestionBody
Text('asdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \nasdasd \n'),
],
),
),
SizedBox(height: 30),
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [TextButton(onPressed: () {}, child: Text("Show Answer"))],
),
],
),
),
),
),
);
}
}
Now, your QuestionBody also seems to have some unnecessary stuff.
Instead of having,
return Column(
children: [
Expanded(
child: Column(
children: [
Text( //Question
Just do,
return Column(
children: [
Text( //Question
Finally remove the height restriction from the CarouselOptions since we already gave that height to the Container inside the Card.

Either give your parent widget more height or wrap your text inside a SingleChildScrollView for example to make the text scrollable

Related

Flutter SingelChildScrollView for column is not working

I have the following code in flutter. The first Expanded with flex 1 can be scrolled if needed but the next Expanded with flex 2 and the list of widgets (createButtons(answerList)) can not be scrolled and I can not figure out why? Both have the scrollable in them!
import 'package:flutter/material.dart';
import '../../backend/QuestionaireConstants/question.dart';
import '../../backend/utils/constants.dart';
import '../../backend/utils/setupcomingRoute.dart';
import '../../backend/widgets/button_content.dart';
import '../../backend/widgets/reusable_cart.dart';
int selectedAnswer = -1;
int counter = 0;
Color determineColor(int selection) {
return selectedAnswer == selection ? Colors.white : Colors.black;
}
class SelectionWindow extends StatefulWidget {
const SelectionWindow({Key? key}) : super(key: key);
#override
_SelectionWindowState createState() => _SelectionWindowState();
}
class _SelectionWindowState extends State<SelectionWindow> {
#override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as List<Question>;
int count = args[0].counter;
int arraylen = args.length;
List answerList = args[count].possibleAnswers;
String upcomingRoute = setUpcomingRoute(count, arraylen, args);
List<Widget> createButtons(list) {
List<Widget> buttons = [];
//creating single choice buttons
for (var i = 0; i < list.length; i++) {
buttons.add(
Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedAnswer = i;
});
},
child: ReusableCard(
colour: selectedAnswer == i
? Colors.blue.shade900
: Colors.blue.shade200,
cardChild: ButtonContent(
label: args[count].possibleAnswers[i],
textColour: determineColor(i),
),
),
),
),
],
),
);
}
return buttons;
}
//showing error screen
Future<void> _showMyDialog() async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Alert'),
content: SingleChildScrollView(
child: ListBody(
children: const <Widget>[
Text('Please select one answer before continuing.'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text(
'Approve',
style: TextStyle(fontSize: 22),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
return Scaffold(
appBar: AppBar(
iconTheme: backwardsArrowBlack,
automaticallyImplyLeading: false,
title: appBarText,
backgroundColor: Colors.blue.shade100,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(args[count].questionText,
style: multipleChoiceTextStyle),
),
),
),
Expanded(
flex: 2,
child: Column(
children: [
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: createButtons(answerList),
),
),
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: GestureDetector(
onTap: () {
if (args[0].counter > 0) {
args[0].counter -= 1;
args[count - 1].givenAnswers.clear();
}
Navigator.pop(context);
},
child: backwardsButton,
),
),
Expanded(
child: GestureDetector(
onTap: () {
if (selectedAnswer == -1) {
_showMyDialog();
} else {
args[count].givenAnswers.add(args[count]
.possibleAnswers[selectedAnswer]);
selectedAnswer = -1;
if (args[0].counter == arraylen - 1) {
args[0].counter += 1;
Navigator.pushNamed(context, '/endScreen',
arguments: args)
.then((_) => setState(() {}));
} else {
args[0].counter += 1;
Navigator.pushNamed(
context,
upcomingRoute,
arguments: args,
).then((_) => setState(() {}));
}
}
},
child: forwardButton,
),
),
],
),
),
),
],
),
),
],
),
);
}
}
The emulator shows the following error in case of having many answers in the list that are not fit in the page:
====================================================================================================
D/EGL_emulation(15191): app_time_stats: avg=10.35ms min=0.79ms max=89.84ms count=52
D/EGL_emulation(15191): app_time_stats: avg=104.68ms min=0.77ms max=1043.27ms count=11
D/EGL_emulation(15191): app_time_stats: avg=69.44ms min=11.30ms max=1017.83ms count=19
I/flutter (15191): type 'Null' is not a subtype of type 'FutureOr<int>'
D/EGL_emulation(15191): app_time_stats: avg=151.10ms min=0.54ms max=925.70ms count=12
======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 203 pixels on the bottom.
This worked:
import 'package:flutter/material.dart';
import '../../backend/QuestionaireConstants/question.dart';
import '../../backend/utils/constants.dart';
import '../../backend/utils/setupcomingRoute.dart';
import '../../backend/widgets/button_content.dart';
import '../../backend/widgets/reusable_cart.dart';
int selectedAnswer = -1;
int counter = 0;
Color determineColor(int selection) {
return selectedAnswer == selection ? Colors.white : Colors.black;
}
class SelectionWindow extends StatefulWidget {
const SelectionWindow({Key? key}) : super(key: key);
#override
_SelectionWindowState createState() => _SelectionWindowState();
}
class _SelectionWindowState extends State<SelectionWindow> {
#override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as List<Question>;
int count = args[0].counter;
int arraylen = args.length;
List answerList = args[count].possibleAnswers;
String upcomingRoute = setUpcomingRoute(count, arraylen, args);
List<Widget> createButtons(list) {
List<Widget> buttons = [];
//creating single choice buttons
for (var i = 0; i < list.length; i++) {
buttons.add(
Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
selectedAnswer = i;
});
},
child: ReusableCard(
colour: selectedAnswer == i
? Colors.blue.shade900
: Colors.blue.shade200,
cardChild: ButtonContent(
label: args[count].possibleAnswers[i],
textColour: determineColor(i),
),
),
),
),
],
),
);
}
return buttons;
}
//showing error screen
Future<void> _showMyDialog() async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Alert'),
content: SingleChildScrollView(
child: ListBody(
children: const <Widget>[
Text('Please select one answer before continuing.'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text(
'Approve',
style: TextStyle(fontSize: 22),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
return Scaffold(
appBar: AppBar(
iconTheme: backwardsArrowBlack,
automaticallyImplyLeading: false,
title: appBarText,
backgroundColor: Colors.blue.shade100,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(args[count].questionText,
style: multipleChoiceTextStyle),
),
),
),
Expanded(
flex: 2,
child: SingleChildScrollView(
child: Column(
children: createButtons(answerList),
),
),
),
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: GestureDetector(
onTap: () {
if (args[0].counter > 0) {
args[0].counter -= 1;
args[count - 1].givenAnswers.clear();
}
Navigator.pop(context);
},
child: backwardsButton,
),
),
Expanded(
child: GestureDetector(
onTap: () {
if (selectedAnswer == -1) {
_showMyDialog();
} else {
args[count].givenAnswers.add(args[count]
.possibleAnswers[selectedAnswer]);
selectedAnswer = -1;
if (args[0].counter == arraylen - 1) {
args[0].counter += 1;
Navigator.pushNamed(context, '/endScreen',
arguments: args)
.then((_) => setState(() {}));
} else {
args[0].counter += 1;
Navigator.pushNamed(
context,
upcomingRoute,
arguments: args,
).then((_) => setState(() {}));
}
}
},
child: forwardButton,
),
),
],
),
),
),
],
),
);
}
}

i can't see my images on carousel slider before i hot reload

hello everyone i am new in flutter. i have a problem, when i start the application i cant see my images on carousel but when i hot reload i can see them. I think that if i put if/else condition it might work but i could not do it can some one help me about that?
here are the codes;
import 'dart:convert';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:feedme_start/widgets/Navigation_Drawer_Widget.dart';
import 'package:flutter/material.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:http/http.dart';
import 'model/AnaEkran_modeli.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
#override
_MyAppState createState() => _MyAppState();
}
final imageList = [];
int ct = imageList.length;
class _MyAppState extends State<MyApp> {
String cevap = "";
late Apianaekran _apianaekran;
late Result _result;
get Index => null;
//"getapidata" adlı future methodda apilerle resimleri çekiyorum sonra imageListe ekliyorum
Future<void> getapidata() async {
String url =
"https://www.mobilonsoft.com/fpsapi/default.aspx?op=application_initialization_customer&firmuid=feedmekktc&device_id=web_20210813180900001&device_platform=4&lang=en";
Response responsee = await get(Uri.parse(url));
if (responsee.statusCode == 200) {
//statusCode 200 oldumu bağlantı siteyle doğru şekilde kuruldu demektir.
Map cevapjson =
jsonDecode(responsee.body); //cevap, json code daki body i alır.
Apianaekran ekran = Apianaekran.fromJson(cevapjson);
ct = ekran.result.sliderImages.length;
print(ct);
int i = 0;
while (i < ct) {
imageList.add(ekran.result.sliderImages[i].imageUrl);
print(ekran.result.sliderImages[i].imageUrl);
i++;
}
} else {
print("bir sorun oluştu");
}
print("resimler başarıyla çekildi");
print(imageList.length);
}
#override
void initState() {
getapidata();
}
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.red,
title: Center(child: Text("FEED ME")),
actions: <Widget>[
IconButton(onPressed: () {}, icon: Icon(Icons.call))
],
),
drawer: NavigationDrawerWidget(),
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Column(
children: [
Container(
constraints: BoxConstraints.expand(height: 200),
child: CarouselSlider(
options: CarouselOptions(
enlargeCenterPage: true,
enableInfiniteScroll: true,
autoPlay: true),
items: imageList
.map((e) => ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.network(
e,
width: 1050,
height: 350,
fit: BoxFit.cover,
)
],
),
))
.toList())), //imageSlider(context),),
/* Divider(,,
color: Colors.red,
),*/
SizedBox(
height: 75,
),
ElevatedButton.icon(
onPressed: () {
getapidata();
}, //api çekiminin denemesini bu tuşnan yaparım şimdilik
icon: Icon(Icons.add),
label: Text("Yeni Sipariş Ver"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red)),
),
SizedBox(
height: 50,
),
// Text(_anaEkranJsonlar.statusCodeDescription),
SizedBox(
height: 150,
),
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () {},
icon: Icon(Icons.add),
label: Text("Canlı Destek"),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red[900])),
),
),
SizedBox(
width: 5,
),
Expanded(
child: ElevatedButton.icon(
onPressed: () {},
icon: Icon(Icons.sms),
label: Text("Fırsatlar"),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red[900])),
),
),
],
),
SizedBox(
height: 30,
),
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () {},
icon: Icon(Icons.exit_to_app),
label: Text("Giriş"),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red[900])),
),
),
SizedBox(
width: 5,
),
Expanded(
child: ElevatedButton.icon(
onPressed: () {},
icon: Icon(Icons.person_add),
label: Text("Kayıt Ol"),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red[900])),
),
),
],
)
],
),
)
/*Swiper(itemCount: imageList.length,
itemBuilder: (context, index) {
return Image.network(imageList[index],/*errorBuilder:
(BuildContext context, Object exception, StackTrace? stackTrace), {return const("resim yüklenemedi")},*/
fit: BoxFit.cover,);
},)*/
),
);
}
}
this is the picture of first start
this one is after i hot reload the code
it has to be like in 2nd pic. can someone help me ?
You need to update the state of your widget inside getapidata after you've loaded all the images:
Future<void> getapidata() async {
String url = "https://www.mobilonsoft.com/fpsapi/default.aspx?op=application_initialization_customer&firmuid=feedmekktc&device_id=web_20210813180900001&device_platform=4&lang=en";
Response responsee = await get(Uri.parse(url));
if (responsee.statusCode == 200) {
// ...
setState(() {});
}
}
The above will already work as expected, but you should consider using a FutureBuilder. Also, you should put
final imageList = [];
int ct = imageList.length;
inside your widget's state, and not in the global scope.

how to show the text in full (Flutter)?

how to show the text in full?
I'm getting this error (on the screen).
what should I change in my code?
Is there any way to do it? In case you want to see the code please let me know I will update more.
read_mode.dart
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:quiz2/const/state.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:quiz2/database/category_provider.dart';
import 'package:quiz2/database/db_helper.dart';
import 'package:quiz2/database/question_provider.dart';
import 'package:quiz2/model/user_answer_model.dart';
import 'package:quiz2/utils/utils.dart';
import 'package:quiz2/widgets/question_body.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ReadModePage extends StatefulWidget {
ReadModePage({Key key, this.title}):super(key: key);
final String title;
#override
_ReadModePageState createState() => _ReadModePageState();
}
class _ReadModePageState extends State<ReadModePage> {
SharedPreferences prefs;
int indexPage = 0;
CarouselController buttonCarouselController = CarouselController();
List<UserAnswer> userAnswers = new List<UserAnswer>();
#override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async{
prefs = await SharedPreferences.getInstance();
indexPage = await prefs.getInt("${context.read(questionCategoryState).state.name}_${context.read(questionCategoryState).state.ID}") ?? 0;
print('Save index page: ${indexPage}');
Future.delayed(Duration(milliseconds: 500)).then((value) => buttonCarouselController.animateToPage(indexPage));
});
}
#override
Widget build(BuildContext context) {
var questionModule = context.read(questionCategoryState).state;
return WillPopScope(child: Scaffold(
appBar: AppBar(title: Text(questionModule.name),
leading: GestureDetector(onTap: () => showCloseDialog(questionModule),
child: Icon(Icons.arrow_back), ),),
body: Container(
color: Colors.teal[100],
child: FutureBuilder<List<Question>>(
future: getQuestionByCategory(questionModule.ID),
builder: (context, snapshot){
if(snapshot.hasError)
return Center(
child: Text('${snapshot.error}'),);
else if(snapshot.hasData)
{
if(snapshot.data.length>0)
{
return Container(margin: const EdgeInsets.all(5.0),
alignment: Alignment.topCenter,
child: Card(
elevation: 20,
child: Container(
child: SingleChildScrollView(
child: Column(children: [
SizedBox(height: 15,),
QuestionBody(context: context,
carouselController: buttonCarouselController,
questions: snapshot.data,
userAnswers: userAnswers,),
SizedBox(height: 30,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(onPressed: () => showAnswer(context), child: Text("Show Answer"))
],)
],)
)
)
));
}
else return Center(
child: Text('Category don\'n have any question'));
} else
return Center(
child: CircularProgressIndicator(),);
}
),
),
), onWillPop: () async{
showCloseDialog(questionModule);
return true;
});
}
showCloseDialog(Category questionModule) {
showDialog(
context: context,
builder:(_) => new AlertDialog(
title: Text('Close'),
content: Text("Do you want to save this question index?"),
actions: [
TextButton(onPressed: (){
Navigator.of(context).pop(); //close dialog
Navigator.pop(context); //close screen
}, child: Text("No")),
TextButton(onPressed: (){
prefs.setInt("${context.read(questionCategoryState).state.name}_${context.read(questionCategoryState).state.ID}",
context.read(currentReadPage).state);
Navigator.of(context).pop(); //close dialog
Navigator.pop(context); //close screen
}, child: Text("Yes"))
],)
);
}
}
Future <List<Question>> getQuestionByCategory(int id) async{
var db = await copyDB();
var result = await QuestionProvider().getQuestionCategoryId(db, id);
return result;
}
question_body.dart
import 'package:auto_size_text/auto_size_text.dart';
import 'package:carousel_slider/carousel_controller.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:quiz2/const/state.dart';
import 'package:quiz2/database/question_provider.dart';
import 'package:quiz2/model/user_answer_model.dart';
import 'package:flutter/material.dart';
import 'package:quiz2/utils/utils.dart';
class QuestionBody extends StatelessWidget {
QuestionBody({Key key,
this.context,
this.userAnswers,
this.carouselController,
this.questions}):super(key:key);
BuildContext context;
List<UserAnswer> userAnswers;
CarouselController carouselController;
List<Question> questions;
#override
Widget build(BuildContext context){
return CarouselSlider(
carouselController: carouselController,
items: questions.asMap().entries.map((e) => Builder(
builder: (context) {
return Consumer(builder: (context, watch, _){
var userAnswerState = watch(userAnswerSelected).state;
var isShowAnswer = watch(isEnableShowAnswer).state;
return Column(
children: [
Expanded(
child: Column(
children: [
Text( //Question
context.read(isTestMode).state ? "${e.key+1}: ${e.value.questionText}":
"${e.value.questionId}: ${e.value.questionText}",
style: TextStyle(height:2, fontSize: 16)),
Visibility(//Question is image
visible: (e.value.isImageQuestion == null || e.value.isImageQuestion == 0 ? false:true),
child: Container(
height: MediaQuery.of(context).size.height/15*2,
child: e.value.isImageQuestion == 0 ? Container():
Image.network("${e.value.questionImage}",
fit: BoxFit.fill,)
)),
Expanded( //Answer A
child: ListTile(
title: AutoSizeText('${e.value.answerA}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'A' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "A",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
)),
Expanded( //Answer B
child: ListTile(
title: AutoSizeText('${e.value.answerB}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'B' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "B",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
)),
Expanded( //Answer C
child: ListTile(
title: AutoSizeText('${e.value.answerC}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'C' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "C",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
)),
Expanded( //Answer D
child: ListTile(
title: AutoSizeText('${e.value.answerD}',
style: TextStyle(color: isShowAnswer ? e.value.correctAnswer == 'D' ? Colors.red : Colors.grey:Colors.black),
),
leading: Radio(
value: "D",
groupValue: getGroupValue(isShowAnswer,e,userAnswerState),
onChanged: (value) => setUserAnswer(context,e,value),
),
))
],
)),
],
);
},
);
},
)).toList(), options: CarouselOptions(
autoPlay: false,
enlargeCenterPage: true,
viewportFraction: 0.9,
initialPage: 0,
height: MediaQuery.of(context).size.height/5*2,
onPageChanged: (page,_){
context.read(currentReadPage).state = page;
context.read(isEnableShowAnswer).state = false;
}
));
}
getGroupValue(bool isShowAnnswer, MapEntry<int, Question> e, UserAnswer userAnswerState){
return isShowAnnswer ? e.value.correctAnswer : (context.read(isTestMode).state ?
context.read(userListAnswer).state[e.key].answered:'');
}
}
screen
Is there any way to do it? In case you want to see the code please let me know I will update more.
Try moving SingleChildScrollView after if condition like that:
if(snapshot.data.length>0) {
return SingleChildScrollView(
child: Container(margin: const EdgeInsets.all(5.0),
alignment: Alignment.topCenter,
child: Card(
elevation: 20,
....

Why isn't Navigator.pop() refreshing data?

Hi guys I'm trying to build an app with flutter, so I have two screens HomeScreen() and RoutineScreen(). The first one is a Scaffold and in the body has a child Widget (a ListView called RoutinesWidget()) with all the routines. And the second one is to create a routine. The thing is, that when I create the routine, I use a button to pop to the HomeScreen() but it doesn't refresh the ListView (I'm guessing that it's because when I use Navigator.pop() it refreshes the Scaffold but not the child Widget maybe?)
HomeScreen() code here:
import 'package:flutter/material.dart';
import 'package:workout_time/constants.dart';
import 'package:workout_time/Widgets/routines_widget.dart';
import 'package:workout_time/Widgets/statistics_widget.dart';
import 'package:workout_time/Screens/settings_screen.dart';
import 'package:workout_time/Screens/routine_screen.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _selectedIndex = 0;
List<Widget> _views = [
RoutinesWidget(),
StatisticsWidget(),
];
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kThirdColor,
appBar: AppBar(
leading: Icon(Icons.adb),
title: Text("Workout Time"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.settings),
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => SettingsScreen()))),
],
),
body: _views[_selectedIndex],
floatingActionButton: (_selectedIndex == 1)
? null
: FloatingActionButton(
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RoutineScreen(null)));
setState(() {});
},
child: Icon(
Icons.add,
color: kSecondColor,
size: 30.0,
),
elevation: 15.0,
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
bottomItems(Icon(Icons.fitness_center_rounded), "Routines"),
bottomItems(Icon(Icons.leaderboard_rounded), "Statistics"),
],
currentIndex: _selectedIndex,
onTap: (int index) => setState(() => _selectedIndex = index),
),
);
}
}
BottomNavigationBarItem bottomItems(Icon icon, String label) {
return BottomNavigationBarItem(
icon: icon,
label: label,
);
}
RoutinesWidget() code here:
import 'package:flutter/material.dart';
import 'package:workout_time/Services/db_crud_service.dart';
import 'package:workout_time/Screens/routine_screen.dart';
import 'package:workout_time/constants.dart';
import 'package:workout_time/Models/routine_model.dart';
class RoutinesWidget extends StatefulWidget {
#override
_RoutinesWidgetState createState() => _RoutinesWidgetState();
}
class _RoutinesWidgetState extends State<RoutinesWidget> {
DBCRUDService helper;
#override
void initState() {
super.initState();
helper = DBCRUDService();
}
#override
Widget build(BuildContext context) {
return FutureBuilder(
future: helper.getRoutines(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
Routine routine = Routine.fromMap(snapshot.data[index]);
return Card(
margin: EdgeInsets.all(1.0),
child: ListTile(
leading: CircleAvatar(
child: Text(
routine.name[0],
style: TextStyle(
color: kThirdOppositeColor,
fontWeight: FontWeight.bold),
),
backgroundColor: kAccentColor,
),
title: Text(routine.name),
subtitle: Text(routine.exercises.join(",")),
trailing: IconButton(
icon: Icon(Icons.delete_rounded),
color: Colors.redAccent,
onPressed: () {
setState(() {
helper.deleteRoutine(routine.id);
});
},
),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RoutineScreen(routine))),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
color: kSecondColor,
);
},
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
);
}
}
RoutineScreen() code here:
import 'package:flutter/material.dart';
import 'package:workout_time/Models/routine_model.dart';
import 'package:workout_time/Widgets/type_card_widget.dart';
import 'package:workout_time/constants.dart';
import 'package:workout_time/Services/db_crud_service.dart';
class RoutineScreen extends StatefulWidget {
final Routine _routine;
RoutineScreen(this._routine);
#override
_RoutineScreenState createState() => _RoutineScreenState();
}
class _RoutineScreenState extends State<RoutineScreen> {
DBCRUDService helper;
final _nameController = TextEditingController();
final _descriptionController = TextEditingController();
bool _type = true;
int _cycles = 1;
int _restBetweenExercises = 15;
int _restBetweenCycles = 60;
#override
void initState() {
super.initState();
helper = DBCRUDService();
}
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.pop(context),
),
title: widget._routine != null
? Text(widget._routine.name)
: Text("Create your routine"),
actions: [
IconButton(
icon: Icon(Icons.done_rounded),
onPressed: createRoutine,
)
],
bottom: TabBar(
tabs: [
Tab(
text: "Configuration",
),
Tab(
text: "Exercises",
),
],
),
),
body: TabBarView(children: [
//_routine == null ? ConfigurationNewRoutine() : Text("WIDGET N° 1"),
ListView(
children: [
Container(
padding: EdgeInsets.all(15.0),
child: Row(
children: [
Text(
"Name:",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(
width: 40.0,
),
Expanded(
child: TextField(
textAlign: TextAlign.center,
controller: _nameController,
),
),
],
),
),
SizedBox(
height: 20.0,
),
Card(
margin: EdgeInsets.all(15.0),
color: kSecondColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
child: Container(
padding: EdgeInsets.all(15.0),
child: Column(
children: [
Text(
"Type",
style: TextStyle(fontSize: 25.0),
),
Row(
children: [
Expanded(
child: TypeCard(
Icons.double_arrow_rounded,
_type == true ? kFirstColor : kThirdColor,
() => setState(() => _type = true),
"Straight set",
),
),
Expanded(
child: TypeCard(
Icons.replay_rounded,
_type == false ? kFirstColor : kThirdColor,
() => setState(() => _type = false),
"Cycle",
),
),
],
),
],
),
),
),
SizedBox(
height: 20.0,
),
Container(
padding: EdgeInsets.all(15.0),
child: Row(
children: [
Text(
"N° cycles:",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(
width: 40.0,
),
Expanded(
child: Text("Hello"),
),
],
),
),
SizedBox(
height: 20.0,
),
],
),
Text("WIDGET N° 2"),
]),
),
);
}
void createRoutine() {
List<String> _exercises = ["1", "2"];
List<String> _types = ["t", "r"];
List<String> _quantities = ["30", "20"];
Routine routine = Routine({
'name': _nameController.text,
'description': "_description",
'type': _type.toString(),
'cycles': 1,
'numberExercises': 2,
'restBetweenExercises': 15,
'restBetweenCycles': 60,
'exercises': _exercises,
'types': _types,
'quantities': _quantities,
});
setState(() {
helper.createRoutine(routine);
Navigator.pop(context);
});
}
}
Any idea what can I do to make it work? Thank you
Make it simple
use Navigator.pop() twice
so that the current class and old class in also removed
from the stack
and then use Navigator.push()
When you push a new Route, the old one still stays in the stack. The new route just overlaps the old one and forms like a layer above the old one. Then when you pop the new route, it will just remove the layer(new route) and the old route will be displayed as it was before.
Now you must be aware the Navigator.push() is an asynchronous method and returns a Future. How it works is basically when you perform a Navigator.push(), it will push the new route and will wait for it to be popped out. Then when the new route is popped, it returns a value to the old one and that when the future callback will be executed.
Hence the solution you are looking for is add a future callback like this after your Navigator.push() :
Navigator.push(context,
MaterialPageRoute(builder: (context) => SettingsScreen())
).then((value){setState(() {});}); /// A callback which is executed after the new route will be popped. In that callback, you simply call a setState and refresh the page.

How to create searchable ListView in popup flutter?

How it possible to create a listView with Search function in a popup flutter?
I call the listView using API laravel. I want data in the popup will be able to be select or user can search it in popup and then select it. As user select the data and click submit data will be able to post in database.
below is the function that I used to call the data
List _listViewData = List();
#override
initState() {
super.initState();
// when loading your widget for the first time, loads country from db
_countryA();
}
void _countryA() async {
// gets data from db
final countryA = await CallApi().getData('countries');
var resBody = json.decode(countryA.body);
setState(() {
// converts db row data to List<String>, updating state
_listViewData = resBody;
});
}
I just know how to call the data of country using dropdown in an alert button.
I dont want it to be display in dropdown but instead in a list in flutter.
below is function that I called in the dropdown
void _showDialog() {
// flutter defined function
showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return AlertDialog(
title: new Text("Select Country", textAlign:TextAlign.center,),
actions: <Widget>[
// usually buttons at the bottom of the dialog
new FlatButton(
child: new Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
content: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: DropdownButton(
items: _listViewData.map((item) {
return new DropdownMenuItem(
child: new Text(item['country']),
value: item['id'].toString(),
);
}).toList(),
onChanged: (newVal) {
setState(() {
_mySelectionAr = newVal;
});
},
value: _mySelectionAr,
),
),
],
),
);
},
);
}
So, the conclusion is that I want it to be display in listview in the flutter popup not a dropdown in a popup. I just cannot figure out how to call all the list data of country in a list in popup include with the search function.
Edit
The most simple way is after folk this github.
You can update file https://github.com/figengungor/country_pickers/blob/master/lib/countries.dart directly
or in
https://github.com/figengungor/country_pickers/blob/master/lib/country_picker_dialog.dart at line 113 change _allCountries to what you need, you can hard code or use your own ready made api but need to follow owner's Country Class.
You can use https://pub.dev/packages/country_pickers directly or reference source code and build your own
for Counties you need does not exist. you can fork this github project and modify directly https://github.com/figengungor/country_pickers/blob/master/lib/countries.dart
It support features you need can use in showDialog and inside is a ListView
also provide search by phone and name
full example code
import 'package:country_pickers/country.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:country_pickers/country_pickers.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Country Pickers Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
routes: {
'/': (context) => DemoPage(),
},
);
}
}
class DemoPage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<DemoPage> {
Country _selectedDialogCountry =
CountryPickerUtils.getCountryByPhoneCode('90');
Country _selectedFilteredDialogCountry =
CountryPickerUtils.getCountryByPhoneCode('90');
Country _selectedCupertinoCountry =
CountryPickerUtils.getCountryByIsoCode('tr');
Country _selectedFilteredCupertinoCountry =
CountryPickerUtils.getCountryByIsoCode('DE');
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Country Pickers Demo'),
),
body: ListView(
padding: EdgeInsets.all(8.0),
children: <Widget>[
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('CountryPickerDropdown'),
ListTile(title: _buildCountryPickerDropdown(false)),
],
),
),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('CountryPickerDropdown (filtered)'),
ListTile(title: _buildCountryPickerDropdown(true)),
],
),
),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('CountryPickerDialog'),
ListTile(
onTap: _openCountryPickerDialog,
title: _buildDialogItem(_selectedDialogCountry),
),
],
),
),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('CountryPickerDialog (filtered)'),
ListTile(
onTap: _openFilteredCountryPickerDialog,
title: _buildDialogItem(_selectedFilteredDialogCountry),
),
],
),
),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('CountryPickerCupertino'),
ListTile(
title: _buildCupertinoSelectedItem(_selectedCupertinoCountry),
onTap: _openCupertinoCountryPicker,
),
],
),
),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('CountryPickerCupertino (filtered)'),
ListTile(
title: _buildCupertinoSelectedItem(
_selectedFilteredCupertinoCountry),
onTap: _openFilteredCupertinoCountryPicker,
),
],
),
),
],
),
);
}
_buildCountryPickerDropdown(bool filtered) => Row(
children: <Widget>[
CountryPickerDropdown(
initialValue: 'AR',
itemBuilder: _buildDropdownItem,
itemFilter: filtered
? (c) => ['AR', 'DE', 'GB', 'CN'].contains(c.isoCode)
: null,
onValuePicked: (Country country) {
print("${country.name}");
},
),
SizedBox(
width: 8.0,
),
Expanded(
child: TextField(
decoration: InputDecoration(labelText: "Phone"),
),
)
],
);
Widget _buildDropdownItem(Country country) => Container(
child: Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(
width: 8.0,
),
Text("+${country.phoneCode}(${country.isoCode})"),
],
),
);
Widget _buildDialogItem(Country country) => Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(width: 8.0),
Text("+${country.phoneCode}"),
SizedBox(width: 8.0),
Flexible(child: Text(country.name))
],
);
void _openCountryPickerDialog() => showDialog(
context: context,
builder: (context) => Theme(
data: Theme.of(context).copyWith(primaryColor: Colors.pink),
child: CountryPickerDialog(
titlePadding: EdgeInsets.all(8.0),
searchCursorColor: Colors.pinkAccent,
searchInputDecoration: InputDecoration(hintText: 'Search...'),
isSearchable: true,
title: Text('Select your phone code'),
onValuePicked: (Country country) =>
setState(() => _selectedDialogCountry = country),
itemBuilder: _buildDialogItem)),
);
void _openFilteredCountryPickerDialog() => showDialog(
context: context,
builder: (context) => Theme(
data: Theme.of(context).copyWith(primaryColor: Colors.pink),
child: CountryPickerDialog(
titlePadding: EdgeInsets.all(8.0),
searchCursorColor: Colors.pinkAccent,
searchInputDecoration: InputDecoration(hintText: 'Search...'),
isSearchable: true,
title: Text('Select your phone code'),
onValuePicked: (Country country) =>
setState(() => _selectedFilteredDialogCountry = country),
itemFilter: (c) => ['AR', 'DE', 'GB', 'CN'].contains(c.isoCode),
itemBuilder: _buildDialogItem)),
);
void _openCupertinoCountryPicker() => showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return CountryPickerCupertino(
backgroundColor: Colors.black,
itemBuilder: _buildCupertinoItem,
pickerSheetHeight: 300.0,
pickerItemHeight: 75,
initialCountry: _selectedCupertinoCountry,
onValuePicked: (Country country) =>
setState(() => _selectedCupertinoCountry = country),
);
});
void _openFilteredCupertinoCountryPicker() => showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return CountryPickerCupertino(
backgroundColor: Colors.white,
pickerSheetHeight: 200.0,
initialCountry: _selectedFilteredCupertinoCountry,
onValuePicked: (Country country) =>
setState(() => _selectedFilteredCupertinoCountry = country),
itemFilter: (c) => ['AR', 'DE', 'GB', 'CN'].contains(c.isoCode),
);
});
Widget _buildCupertinoSelectedItem(Country country) {
return Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(width: 8.0),
Text("+${country.phoneCode}"),
SizedBox(width: 8.0),
Flexible(child: Text(country.name))
],
);
}
Widget _buildCupertinoItem(Country country) {
return DefaultTextStyle(
style:
const TextStyle(
color: CupertinoColors.white,
fontSize: 16.0,
),
child: Row(
children: <Widget>[
SizedBox(width: 8.0),
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(width: 8.0),
Text("+${country.phoneCode}"),
SizedBox(width: 8.0),
Flexible(child: Text(country.name))
],
),
);
}
}