class Drawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
accountName: Text("Anus"),
accountEmail: Text("Anus@gmail.com"),
currentAccountPicture: CircleAvatar(
backgroundImage: NetworkImage(
"https://images.unsplash.com/photo-1533227268428-f9ed0900fb3b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1158&q=80"),
),
),
ListTile(
leading: Icon(Icons.person),
title: Text("Account"),
subtitle: Text("Personal"),
trailing: Icon(Icons.edit),
),
ListTile(
leading: Icon(Icons.email),
title: Text("Email"),
subtitle: Text("anus@gmail.com"),
trailing: Icon(Icons.send),
),
],
),
);
}
}
如何解决该问题
我想创建抽屉,但是当我尝试在抽屉的新文件中创建抽屉时未定义命名参数'child'。
答案 0 :(得分:0)
您在定义该小部件时使用了相同的小部件。
这是有效的代码。
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> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _buildBody() {
return Drawer();
}
}
class Drawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView(
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
accountName: Text("Anus"),
accountEmail: Text("Anus@gmail.com"),
currentAccountPicture: CircleAvatar(
backgroundImage: NetworkImage(
"https://images.unsplash.com/photo-1533227268428-f9ed0900fb3b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1158&q=80"),
),
),
ListTile(
leading: Icon(Icons.person),
title: Text("Account"),
subtitle: Text("Personal"),
trailing: Icon(Icons.edit),
),
ListTile(
leading: Icon(Icons.email),
title: Text("Email"),
subtitle: Text("anus@gmail.com"),
trailing: Icon(Icons.send),
),
],
);
}
}