【发布时间】:2019-11-09 03:08:48
【问题描述】:
我有一个文本字段,用户在其中输入一个数字和一个 Raisedbutton。通过单击该按钮,用户应该能够拨打该号码。如何为那个按钮编写 onPressed() 函数??
在这段代码之上,我有我的主类,其中 Home() 类被调用
import 'package:flutter/material.dart';
class Home extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return HomeState();
}
}
class HomeState extends State<Home> {
TextEditingController numcontroller = new TextEditingController();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.deepPurple,
title: Text('Calling App'),
),
body: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 60.0, left: 10.0, right: 10.0),
child: TextField(
controller: numcontroller,
decoration: InputDecoration(
labelText: 'Enter Phone Number',
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple,
)
)
)
),
),
Container(
height: 45.0,
width: 90.0,
margin: EdgeInsets.only(top: 40, left: 10, right: 10.0),
child: RaisedButton(
color: Colors.deepPurple,
elevation: 7.0,
child: Text(
'Call',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: () {
_calling();
}
),
)
],
),
),
);
}
void _calling(){
}
}
假设我输入了一个号码 94********。然后按下该按钮,呼叫应连接到该号码。如果忙或关机,则应显示任何警报消息。
【问题讨论】:
标签: flutter