library aaa1;
part 'bbb.dart';
void fio2() {
print("fio2");
}
void go() {
Person a;
fio1();
fio2();
}
part of aaa1;
String s1 = "lib5";
void fio1() {
fio2();
print("fio1");
}
class Person {
late String name;
late int age;
}
import 'package:flutter/material.dart';
import 'aaa.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'XXX',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyPage(),
);
}
}
class MyPage extends StatefulWidget {
const MyPage({super.key});
@override
State<MyPage> createState() => _MyPageState();
}
class _MyPageState extends State<MyPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
go();
},
child: const Text('XXX')),
),
);
}
}
在aaa.dart文件里
library aaa1;
part 'bbb.dart' //表示bbb.dart是自己的一部分
part 'ccc.dart'
定义这个文件为一个名字为 aaa1 的系列,
然后在bbb.dart文件里 part of aaa1; 说明bbb是aaa的一部分.
part 和 part of 是成对使用的