当前,我有文件目录
"../Model.py"
此模型有一个名为 Test 的类。
使用目录的字符串,我要导入并使用Test类。
我该怎么做?
(字符串将动态更改)
答案 0 :(得分:-1)
发件人:https://docs.python.org/3/tutorial/modules.html#the-module-search-path
我对此进行了测试,我相信它也应该对您有用。该代码应如下所示:
class CardStack extends StatefulWidget {
@override
_CardStackState createState() => new _CardStackState();
}
class _CardStackState extends State<StatefulWidget> {
@override
Widget build(BuildContext context) {
return new Container(
padding: EdgeInsets.all(32),
child: SizedBox.expand(
child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
RenderBox box = context.findRenderObject() as RenderBox;
return new Stack(
children: <Widget>[
new Draggable(
key: ObjectKey('card1'),
child: new Card(
color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Container(
),
),
feedback: new Card(
color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Container(
width: box.size.width, // TODO: how to get same size as child??
height: box.size.height, // TODO: how to get same size as child??
),
),
childWhenDragging: Container(),
),
new Draggable(
key: ObjectKey('card2'),
child: new Card(
color: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Container(
),
),
feedback: new Card(
color: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Container(
width: box.size.width,
height: box.size.height,
),
),
childWhenDragging: Container(),
),
new Listener(
onPointerDown: (PointerDownEvent event) {
print(event.position);
},
child: new Draggable(
key: ObjectKey('card3'),
child: new Card(
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Container(
),
),
feedback: new Card(
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Container(
width: box.size.width,
height: box.size.height,
),
),
childWhenDragging: Container(),
),
),
],
);
}),
),
);
}
}