所以我正在创建一个输入文本的应用程序,当我点击“提交”按钮时,它应该将每个字母转换为其各自的数字并执行数字总和以获得最终的单个数字答案。有人可以指导我如何去做吗?我是 Dart 编程语言的初学者,我似乎无法关联逻辑
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:luckynumberapp/Calculate.dart';
import 'package:luckynumberapp/about.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var name, value;
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: Builder(
builder: (context) => Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.white),
backgroundColor: Colors.red,
title: Text(
'LUCKY NUMBER',
style: TextStyle(fontFamily: 'Pacifico', letterSpacing: 4),
),
),
body: Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 30),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
decoration: InputDecoration(
hintText: 'Enter a word/name',
labelText: 'Enter',
),
keyboardType: TextInputType.text,
onChanged: (name) {
value = name;
value1 = name;
},
),
RaisedButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => screen2(value: value),
));
},
child: Text('Submit'),
),
],
),
),
),
drawer: Drawer(
child: ListView(
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.red),
accountName: Text('Yogesh Prakash'),
accountEmail: Text('test@dev.com'),
currentAccountPicture: CircleAvatar(
child: Image(
image: AssetImage(
'Image/105769079_10217500208479055_1053899048265455769_n.jpg'),
),
),
),
ListTile(
title: Text('About'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AboutPage()),
);
})
],
),
),
),
),
);
}
}