当我尝试将main_screen.dart
支架主体参数包装到column / Row小部件时,但是仅显示应用栏标题。不是支架的身体论点。我想在列/行视图中添加其他一些小部件,这就是为什么它对我至关重要。请描述如何解决此问题。我尝试用容器然后列/行包装它,但没有任何效果。
main.dart
import 'package:app/main_screen.dart';
import 'package:flutter/material.dart';
main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Receipe App',
home: MainScreen(),
);
}
}
main_screen.dart
import 'package:app/detail_page.dart';
import 'package:flutter/material.dart';
import 'dummy.dart';
import 'popular_item.dart';
class MainScreen extends StatelessWidget {
final dummyData = DUMMY_MEALS
.map((meData) => PopularItem(meData.title, meData.id, meData.imgUrl))
.toList();
void selectMeal(BuildContext ctx) {
Navigator.of(ctx).push(
MaterialPageRoute(
builder: (_) {
return DetailPage();
},
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hey Designer'),
),
body: Row(
children: <Widget>[
DetailPage(),
],
)
);
}
}
detail_page.dart
import 'package:flutter/material.dart';
// import 'package:app/detail_page.dart';
// import 'package:flutter/material.dart';
import 'dummy.dart';
import 'popular_item.dart';
class DetailPage extends StatelessWidget {
final dummyData = DUMMY_MEALS
.map((meData) => PopularItem(meData.title, meData.id, meData.imgUrl))
.toList();
void selectMeal(BuildContext ctx) {
Navigator.of(ctx).push(
MaterialPageRoute(
builder: (_) {
return DetailPage();
},
),
);
}
@override
Widget build(BuildContext context) {
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: dummyData.length,
itemBuilder: (ctx, index) {
return Stack(
children: <Widget>[
InkWell(
onTap: ()=>selectMeal(context),
child: Container(
height: 210,
width: 200,
margin: EdgeInsets.all(15),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
gradient: LinearGradient(
colors: [Colors.white, Color(0xFFACBEA3)],
begin: Alignment.topLeft,
end: Alignment.bottomRight),
boxShadow: [
BoxShadow(
color: Colors.black87,
blurRadius: 10.0,
spreadRadius: 0.5,
offset: Offset.fromDirection(20)),
],
),
child: Container(
margin: EdgeInsets.only(
bottom: 45, top: 20, left: 20, right: 20),
// margin: EdgeInsets.only(bottom: 40, top: 5),
// color: Colors.red,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage('images/plate1.png'),
fit: BoxFit.cover,
),
color: Colors.green,
),
),
),
),
Positioned(
top: 190,
left: 12,
height: 40,
child: Container(
child: Text(dummyData[index].title),
width: 200,
margin: EdgeInsets.only(left: 3),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
color: Colors.white,
// boxShadow: [
// BoxShadow(
// color: Colors.black87,
// blurRadius: 10.0,
// spreadRadius: 0.5,
// offset: Offset.fromDirection(60)),
// ],
),
),
)
],
);
});
}
}
popular_item.dart
import 'package:flutter/material.dart';
class PopularItem extends StatelessWidget {
final String title;
final String id;
final String imgUrl;
PopularItem(this.title, this.id,this.imgUrl);
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(25),
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Text(title),
Text(id),
],
),
);
}
}
dummy.dart
import 'popular.dart';
const DUMMY_MEALS = const [
Popular(
id: 'm1',
title: 'Spaghetti with Tomato Sauce',
imgUrl:'https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg/800px-Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg',
),
Popular(
id: 'm1',
title: 'Spaghetti ',
imgUrl:'https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg/800px-Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg',
),
Popular(
id: 'm1',
title: 'Spaghetti with Tomato Sauce',
imgUrl:'https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg/800px-Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg',
),
Popular(
id: 'm1',
title: 'Spaghetti with Tomato Sauce',
imgUrl:'https://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg/800px-Spaghetti_Bolognese_mit_Parmesan_oder_Grana_Padano.jpg',
),
];
popular.dart
class Popular{
final String id;
final String title;
final String imgUrl;
const Popular(
{
this.id,
this.imgUrl,
this.title
}
);
}
答案 0 :(得分:0)
您的描述仍然不清楚,但是根据您的代码,我对发生错误的位置进行了一些更改,只需替换此代码即可
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hey Designer'),
),
body:Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width*0.98,
height: 300,
child: DetailPage(),
),
],
),
Text('Hello')
],
)
);
}
您可能会得到所需的输出。
让我知道它是否有效。
//更新代码
(async() => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.goto(url,{timeout: 0, waitUntil: 'networkidle0'});
const [el]= await page.$x('//*[@id="left"]/div/div[4]/div[3]/div[2]/a/h3/span[1]');
// console.log(el)
const txt = await el.getProperty('textContent');
const rawTxt = await txt.jsonValue();
console.log({rawTxt});
} catch (err) {
console.error(err.message);
} finally {
await browser.close();
}
})();
签出我添加的更新代码,将其添加到主屏幕构建方法中。 让我知道它是否有效