【发布时间】:2021-12-12 01:51:53
【问题描述】:
main.dart 代码
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()),
);
},
),
),
),
]),
));
// ],
//);
}
}
下一个屏幕(calculatedval.dart)代码。
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")
])),
);
}
}
这是我的屏幕输出。
我的控制台输出
W/IInputConnectionWrapper(3079):非活动 InputConnection 上的 getSelectedText W/IInputConnectionWrapper(3079):非活动 InputConnection 上的 requestCursorAnchorInfo 2 W/IInputConnectionWrapper(3079):非活动 InputConnection 上的 getTextBeforeCursor D/InputConnectionAdaptor(3079): 输入法开启光标监控
【问题讨论】:
-
使用
scaffold小部件作为child的MaterialApp
标签: android ios flutter dart user-interface