FormatException: Unexpected character (at character 1) in Flutterinsta Package - flutter

I am using FlutterInsta package. I am getting some information after entering username in textfield. But i am getting this kind of exception after some time.
This is the error :-
I/flutter ( 8708): FormatException: Unexpected character (at character 1)
I/flutter ( 8708):
I/flutter ( 8708): ^
Here is the code :-
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Instainfo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
FlutterInsta flutterInsta = new FlutterInsta();
var text;
String url,followers,following,bio,username,website;
List<String> feed = [];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body:ListView(
shrinkWrap: true,
children: [
TextField(
onChanged: (val) {
text = val;
},
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(Icons.send),
onPressed: () async {
try {
await flutterInsta.getProfileData(text);
setState(() {
followers = flutterInsta.followers;
following = flutterInsta.following;
});
} catch (e) {
print(e);
}
},
),
hintText: "Enter Username",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
),
),
Column(
children: [
Text("Followers :- $followers"),
Text("Following :- $following")
],
),
),
],
),
),
);
}
}
Is there any limit to request this package ?

Related

flutter number textfield with right symbol

i am trying to implement text field with showing symbol of height at the right of the text. for example when user enter any input the TextField must be like:
180 cm
as you see above cm should be appear whenever any text changed and shouldn't be removable.
i am trying to achieve it by using following library but could success. any suggestion?
https://pub.dev/packages/flutter_masked_text2
here is what I tried:
var heightController = MaskedTextController(
mask: '000 cm',
);
you can try this
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Postfix Text Controller',
theme: ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.dark,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final TextEditingController _textController = TextEditingController();
final String _userPostfix = " cm";
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text("Postfix Text Controller"),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextFormField(
controller: _textController,
onChanged: (value) {
if (value == _userPostfix) {
_textController.text = "";
return;
}
value.endsWith(_userPostfix)
? _textController.text = value
: _textController.text = value + _userPostfix;
_textController.selection = TextSelection.fromPosition(
TextPosition(
offset: _textController.text.length -
_userPostfix.length));
},
decoration: const InputDecoration(
labelText: "Height",
border: OutlineInputBorder(),
),
),
],
),
),
),
);
}
}
You can try this
TextField(
controller: _textController,
keyboardType: TextInputType.number,
onChanged: (val) {
_textController.text =
val.replaceAll("c", "").replaceAll("m", "") + " cm";
_textController.selection = TextSelection.fromPosition(
TextPosition(
offset: _textController.text.length - 3));
},
),

Trying to convert TextFormField

I am trying to convert TextEditingController into int because I want to delete the user ID from database by using TextEditingController.
look at: (<-------) in the code to understand.
and here is my code:
import 'package:flutter/material.dart';
import 'package:untitled/database.dart';
import './model/columns.dart';
import './database.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
void dispose() {
textController.dispose();
super.dispose();
}
final textController = TextEditingController();
int? selectedId;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("App"),
),
body: Form(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: textController,
decoration: InputDecoration(
labelText: "Insert row",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25))),
),
),
ElevatedButton(
child: Icon(Icons.save),
onPressed: () async {
await DatabaseHelper.instance
.insert(Users(name: textController.text));
setState(() {
textController.clear();
});
print("Inserted!");
},
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
//controller: selectedId, // <-------
decoration: InputDecoration(
labelText: "Delete ID",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25))),
keyboardType: TextInputType.number,
),
),
ElevatedButton(
child: Icon(Icons.delete),
onPressed: () async {
DatabaseHelper.instance.delete(selectedId!); // <-------
},
),
ElevatedButton(
child: Text("Check all rows"),
onPressed: () async {
print(await DatabaseHelper.instance.queryAll());
},
),
],
),
)),
);
}
}
Create another controller then pass as the entered data as int by converting with int.parse(yourcontroller.text)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
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> {
final textController = TextEditingController();
final numberController = TextEditingController();
#override
void dispose() {
textController.dispose();
numberController.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: numberController,
decoration: InputDecoration(
labelText: "Delete ID",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25))),
keyboardType: TextInputType.number,
),
),
ElevatedButton(
child: Icon(Icons.delete),
onPressed: () async {
DatabaseHelper.instance.delete(int.parse(numberController.text));
print(int.parse(numberController.text));
},
),
],
),
),
);
}
}

Flutter - Choose text from TopDownMenu with a number attached to it and take this number into a calculation

I am here once again asking for your support. I have no idea how to do this.
I have a code that multiplys values from textfields, now i want to add a value from a dropdown menu into the calculation.
Can you please show me how? I have already made a list for the values:
final _materials = const [
{
'Type': [
{'material': 'Stahl', 'dichte': 7.87},
{'material': 'Zamak', 'dichte': 6.7},
{'material': 'Aluminium', 'dichte': 2.7},
],
}
];
I don't know if this is the correct format. The goal is, if you e.g. take "Stahl" from the Dropdown:
DropdownButton(items: null, onChanged: null),
the value "dichte" (7.87) should be put into the calculation:
void _calculation() {
setState(
() {
_volume = int.parse(lenCon.text) *
int.parse(widCon.text) *
int.parse(higCon.text) *
'dichte';
},
);
print(_volume);
}
Here is the complete Code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
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 _volume;
#override
initState() {
_volume = 0;
}
void _calculation() {
setState(
() {
_volume = int.parse(lenCon.text) *
int.parse(widCon.text) *
int.parse(higCon.text) *
'dichte';
},
);
print(_volume);
}
final lenCon = TextEditingController();
final widCon = TextEditingController();
final higCon = TextEditingController();
final _materials = const [
{
'Type': [
{'material': 'Stahl', 'dichte': 7.87},
{'material': 'Zamak', 'dichte': 6.7},
{'material': 'Aluminium', 'dichte': 2.7},
],
}
];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: lenCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Länge',
),
),
TextField(
controller: widCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Breite',
),
),
TextField(
controller: higCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Höhe',
),
),
DropdownButton(items: null, onChanged: null),
RaisedButton(
onPressed: (_calculation),
child: Text('Berechnen'),
),
Text('Your Volume is: $_volume'),
],
),
),
),
);
}
}
Thanks in advance!
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
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> {
double _volume = 0;
double dropValue = 0.0;
var selectedValue;
void _calculation() {
print(lenCon.text +
" " +
widCon.text +
" " +
higCon.text +
" " +
dropValue.toString());
setState(
() {
_volume = int.parse(lenCon.text) *
int.parse(widCon.text) *
int.parse(higCon.text) *
dropValue;
},
);
print(_volume);
}
final lenCon = TextEditingController();
final widCon = TextEditingController();
final higCon = TextEditingController();
final _materialsTypes = [
{'material': 'Stahl', 'dichte': 7.87},
{'material': 'Zamak', 'dichte': 6.7},
{'material': 'Aluminium', 'dichte': 2.7}
];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: lenCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Länge',
),
),
TextField(
controller: widCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Breite',
),
),
TextField(
controller: higCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Höhe',
),
),
DropdownButton(
hint: new Text("Select a Material"),
value: selectedValue,
items: _materialsTypes.map((value) {
return new DropdownMenuItem(
value: value["dichte"],
child: new Text(value["material"]),
);
}).toList(),
onChanged: (item) {
setState(() {
try {
dropValue = item;
selectedValue = item;
} catch (e) {
print(e);
}
});
print(item);
}),
// DropdownButton(items: null, onChanged: null),
RaisedButton(
onPressed: (_calculation),
child: Text('Berechnen'),
),
Text('Your Volume is: $_volume'),
],
),
),
),
);
}
}
here is your solution bro.

how to change the border of a cupertinotextfield when is focused in flutter

I am trying to develop a form using flutter and I need to change the border of my cupertinotextfield when the user focused on it.
You can copy paste run full code below
You can use onFocusChange of FocusScope to check focus and change BoxDecoration to what you need
code snippet
FocusScope(
child: Focus(
onFocusChange: (focus) {
if (focus) {
setState(() {
boxSetting = boxHasFocus;
});
} else {
setState(() {
boxSetting = defaultBoxSetting;
});
}
},
child: CupertinoTextField(
decoration: boxSetting, controller: _textController)))
working demo
full code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
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: 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> {
TextEditingController _textController;
BoxDecoration boxSetting;
BoxDecoration defaultBoxSetting = CupertinoTextField().decoration;
BoxDecoration boxHasFocus = BoxDecoration(
border: Border.all(color: Color(0xFFFFFF00), width: 0.5),
color: Color(0xFF9E9E9E),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular((20.0)),
);
#override
void initState() {
_textController = TextEditingController(text: '');
boxSetting = defaultBoxSetting;
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FocusScope(
child: Focus(
onFocusChange: (focus) {
if (focus) {
setState(() {
boxSetting = boxHasFocus;
});
} else {
setState(() {
boxSetting = defaultBoxSetting;
});
}
},
child: CupertinoTextField(
decoration: boxSetting, controller: _textController))),
],
),
),
);
}
}

DropdownButtonFormField assertion fails where DropdownButtonHideUnderline doesn't

This works with DropdownButtonHideUnderline, but does not work with DropdownButtonFormField. I want the inputDecoration that I get with DropdownButtonFormField, but this code fails at runtime when I change the project.
I either need to fix it to run with DropdownButtonFormField or I should find a way to get the inputDecoration added to the DropdownButtonHideUnderline;
At runtime the error that comes out is:
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 827 pos 15: 'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem<T> item) {
return item.value == value;
}).length == 1'
import 'package:flutter/material.dart';
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: 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();
}
Map data = {
'Project 1': ['Entrance', 'Main Hallway', 'Kitchen'],
'Project 2': ['Patio', 'Dining Room'],
};
class _MyHomePageState extends State<MyHomePage> {
String _project;
String _room;
List<String> _roomList = [];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
children: <Widget>[
DropdownButtonFormField(
decoration: InputDecoration(labelText: 'Project'),
value: _project,
onChanged: (value) {
setState(() {
_project = value;
_room = null;
_roomList = data[_project];
});
},
items: data.keys.map((item) {
return DropdownMenuItem(
child: Text(item),
value: item,
);
})?.toList() ??
[],
),
DropdownButtonFormField(
decoration: InputDecoration(labelText: 'Room'),
value: _room,
onChanged: (value) {
setState(() {
_room = value;
print(_project);
print(_room);
});
},
items: _roomList.map((item) {
return DropdownMenuItem(
child: Text(item),
value: item,
);
})?.toList() ??
[],
),
],
),
));
}
}
You can copy paste run full code below
When Dropdown list data is totally different will trigger this error
For Room DropdownButtonFormField You can use key: UniqueKey() and widget will recreate
code snippet
DropdownButtonFormField(
key: UniqueKey(),
decoration: InputDecoration(labelText: 'Room'),
working demo
full code
import 'package:flutter/material.dart';
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: 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();
}
Map data = {
'Project 1': ['Entrance', 'Main Hallway', 'Kitchen'],
'Project 2': ['Patio', 'Dining Room'],
};
class _MyHomePageState extends State<MyHomePage> {
String _project;
String _room;
List<String> _roomList = [];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
children: <Widget>[
DropdownButtonFormField(
decoration: InputDecoration(labelText: 'Project'),
value: _project,
onChanged: (value) {
setState(() {
_project = value;
_room = null;
_roomList = data[_project];
});
},
items: data.keys.map((item) {
return DropdownMenuItem(
child: Text(item),
value: item,
);
})?.toList() ??
[],
),
DropdownButtonFormField(
key: UniqueKey(),
decoration: InputDecoration(labelText: 'Room'),
value: _room,
onChanged: (value) {
setState(() {
_room = value;
print(_project);
print(_room);
});
},
items: _roomList.map((item) {
return DropdownMenuItem(
child: Text(item),
value: item,
);
})?.toList() ??
[],
),
],
),
));
}
}