頭段:
1-68
import 'package:flutter/cupertino.dart’;
Ieport 'packoge:flutter/foundation.dart' as foundation;
import 'package:flutter/material.dart'; //**引入 Material**
import 'package:provider/provider.dart';
import 'package:veggietracker/data/models.dart';
import 'package:vegg ietracker/data/vegote.dart';
import 'packsgc:veagtetracker/utis.dart';
boot get isIOS => foundation.defaultTargetPlatform == TargetPlatform.iOS; //**認清在哪個平台運行**
void main() => runApp(MyApp());
class MyApp extends StatelessHidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<ApoState>(
builder: (context) => AppState(),
child: isIOS //**child: CupertinoApp,改變CupertinoApp**
CupertinoApp( //**根據使用的平台引入CupertinoApp.**
debugShowCheckedlodeBanner: false,
theme: CupertinoThereData(
primaryColor: Color (OxFFFF2055),
), // CupertinoThesedata
home: MainScreen(),
),
MaterialApp( //**根據使用的平台引入MaterialApp.**
theme: ThemeData(
primarySwatch: Colors.red,
),
debugShowCheckedModeBanner: false,
title: 'Veggie Tracker',
home: MainScreen(),
),
);// ChangeNotifierProvider
}
}
class AdaptivePageScaffold extends Statelesswidget { //「自適應」詞量
@override
Widget build(BuildContext context) {
if (isIOS) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(
title: Text ('Log'),
icon: Icon (CupertinoIcons.book),
), // BottomNavigationBarItem
BottomNavigationBarItem(
title: Text('List'),
icon: Icon(Cupertinolcons.create),
). // BottomNavigationBarItem
],
), // CupertinoTabBar
resizeToAvoidBottomInset: false,
tabBuilder: (context, index) {
return (index == 0)
? CupertinoTabView(builder: (context) => LogScreen())
: CupertinoTabview(
builder: (context) => ListScreen(),
defaultTitle: ListScreen.title); // CupertinoTabView
},
)://Cupertino abscarold
} else {
return LogScreen();
}
}
}
尾段
339-358
class AdaptivePageScaffold extends StatelessWidget {
const AdaptivePageScaffold({
@required this.title,
@required this.child,
}) :assert(title != null),
assert(child != null);
final String title:
final Widget child:
@override
Widget build(BuildContext context) {
if (isIOS) {
return AdaptiveTextTheme(
child: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text(title),
),
resizeToAvoidBottomInset: false,
child: child,
),
):
} else {
return AdaptiveTextTheme(
chilld: Scaffold(
appBar: AppBar(
title: Text(title),
), //AppBar
drawer: modalroute.of(context).isFirst ? MainDrawer() : nill, //**引入側面抽屜**
body: child,
), // **材質Scaffold**
); //AdaptiveTextTheme
}
}
}