Issue
main.dart code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:toggle_switch/toggle_switch.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:mybmiapp/calculatedval.dart';
import 'package:mybmiapp/globals.dart' as globals;
import 'globals.dart' as globals;
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_MyState createState() => _MyState();
}
class _MyState extends State<MyApp> {
bool _isBannerAdReady = false;
var msgController = TextEditingController();
var msgController2 = TextEditingController();
int genderindex = 0;
String text3 = "";
int maxLength = 10;
String kg = "0";
String p = "32";
double? n = null;
double? n2 = null;
double oldVal = 0.00;
double newVal = 0.00;
double oldVal2 = 0.00;
double newVal2 = 0.00;
@override
final heightcon = TextEditingController();
final weightcon = TextEditingController();
Widget build(BuildContext context) {
return MaterialApp(
theme: new ThemeData(backgroundColor: Colors.white),
home: Center(
child: Column(
children: <Widget>[
SizedBox(height: 50),
Material(
elevation: 30.0,
shadowColor: Colors.grey,
child: Container(
color: Colors.transparent,
width: 300,
child: SingleChildScrollView(
child: TextField(
controller: heightcon,
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'textfield',
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: BorderSide(
color: Colors.black,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: BorderSide(
color: Colors.black54,
width: 2.0,
),
),
),
onChanged: (heightval) { },
),
),
),
),
SizedBox(height: 50),
Material(
elevation: 30.0,
shadowColor: Colors.grey,
child: Container(
width: 300,
child: SingleChildScrollView(
child: TextField(
controller: weightcon,
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'textfield',
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: BorderSide(
color: Colors.black,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: BorderSide(
color: Colors.black54,
width: 2.0,
),
),
),
onChanged: (weightval) { },
),
),
),
),
SizedBox(height: 30),
SizedBox(
height: 57,
width: 150,
child: Material(
elevation: 30,
shadowColor: Colors.grey,
child: ElevatedButton(
style: ButtonStyle(
textStyle: MaterialStateProperty.all(TextStyle(
fontSize: 23,
color: Colors.white,
)),
backgroundColor:
MaterialStateProperty.all(Colors.red),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0.0),
side: BorderSide(color: Colors.white)))),
child: Text('button'),
onPressed: () {
print(genderindex);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondRoute()),
);
},
),
),
),
]),
));
// ],
//);
}
}
Next Screen (calculatedval.dart) code.
import 'package:flutter/material.dart';
import 'package:mybmiapp/globals.dart' as globals;
class SecondRoute extends StatelessWidget {
const SecondRoute({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text((globals.weightvalue).toStringAsFixed(2)),
),
body: Center(
child: Column(
children: <Widget>[
SizedBox(
height: 30,
),
Material(
elevation: 30,
shadowColor: Colors.grey,
child: Container(
alignment: Alignment.center,
height: 75,
width: 245,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(0.0),
),
child: Text(
"BMI IS " + (globals.bmi).toStringAsFixed(2),
style: TextStyle(
color: Colors.red,
fontSize: 33,
),
)),
),
SizedBox(
height: 30,
),
Material(
elevation: 30,
shadowColor: Colors.grey,
child: Container(
alignment: Alignment.center,
height: 80,
width: 245,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(0.0),
),
child: Text(
"BMI Level is " + globals.BmiLevel,
style: TextStyle(
color: Colors.black,
fontSize: 33,
),
)),
),
Text("only for 20 years plus")
])),
);
}
}
This is my screen output.
My console output
W/IInputConnectionWrapper( 3079): getSelectedText on inactive InputConnection W/IInputConnectionWrapper( 3079): requestCursorAnchorInfo on inactive InputConnection 2 W/IInputConnectionWrapper( 3079): getTextBeforeCursor on inactive InputConnection D/InputConnectionAdaptor( 3079): The input method toggled cursor monitoring on
Solution
Use Scaffold
or Material
widget wrap your code and don't need to use MaterialApp
I have updated the code little bit take a look
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MaterialApp(
theme: ThemeData(),
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_MyState createState() => _MyState();
}
class _MyState extends State<MyApp> {
bool _isBannerAdReady = false;
var msgController = TextEditingController();
var msgController2 = TextEditingController();
int genderindex = 0;
String text3 = "";
int maxLength = 10;
String kg = "0";
String p = "32";
double? n = null;
double? n2 = null;
double oldVal = 0.00;
double newVal = 0.00;
double oldVal2 = 0.00;
double newVal2 = 0.00;
@override
Widget build(BuildContext context) {
final heightcon = TextEditingController();
final weightcon = TextEditingController();
return Material(
child: Column(children: <Widget>[
const SizedBox(height: 50),
Material(
elevation: 30.0,
shadowColor: Colors.grey,
child: Container(
color: Colors.transparent,
width: 300,
child: SingleChildScrollView(
child: TextField(
controller: heightcon,
style: const TextStyle(
color: Colors.black,
fontSize: 30,
),
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: 'textfield',
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: const BorderSide(
color: Colors.black,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: const BorderSide(
color: Colors.black54,
width: 2.0,
),
),
),
onChanged: (heightval) {},
),
),
),
),
const SizedBox(height: 50),
Material(
elevation: 30.0,
shadowColor: Colors.grey,
child: Container(
width: 300,
child: SingleChildScrollView(
child: TextField(
controller: weightcon,
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'textfield',
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: BorderSide(
color: Colors.black,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(0.0),
borderSide: BorderSide(
color: Colors.black54,
width: 2.0,
),
),
),
onChanged: (weightval) {},
),
),
),
),
SizedBox(height: 30),
SizedBox(
height: 57,
width: 150,
child: Material(
elevation: 30,
shadowColor: Colors.grey,
child: ElevatedButton(
style: ButtonStyle(
textStyle: MaterialStateProperty.all(TextStyle(
fontSize: 23,
color: Colors.white,
)),
backgroundColor: MaterialStateProperty.all(Colors.red),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0.0),
side: BorderSide(color: Colors.white)))),
child: Text('button'),
onPressed: () {
print(genderindex);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
),
),
]),
);
//);
}
}
class SecondRoute extends StatelessWidget {
const SecondRoute({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('(globals.weightvalue).toStringAsFixed(2)'),
),
body: Center(
child: Column(children: <Widget>[
SizedBox(
height: 30,
),
Material(
elevation: 30,
shadowColor: Colors.grey,
child: Container(
alignment: Alignment.center,
height: 75,
width: 245,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(0.0),
),
child: Text(
"BMI IS " + ' (globals.bmi).toStringAsFixed(2)',
style: TextStyle(
color: Colors.red,
fontSize: 33,
),
)),
),
SizedBox(
height: 30,
),
Material(
elevation: 30,
shadowColor: Colors.grey,
child: Container(
alignment: Alignment.center,
height: 80,
width: 245,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.circular(0.0),
),
child: Text(
"BMI Level is " + 'globals.BmiLevel',
style: TextStyle(
color: Colors.black,
fontSize: 33,
),
)),
),
Text("only for 20 years plus")
])),
);
}
}
Answered By - Hemanth S