iT邦幫忙

2023 iThome 鐵人賽

DAY 19
0
自我挑戰組

基礎學習Flutter系列 第 19

Day19-學習[Building for iOS with Flutter]IOS 轉換Android (記錄)

  • 分享至 

  • xImage
  •  

頭段:
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  
     }
   }
 }

上一篇
Day18-學習[Building for iOS with Flutter]IOS 轉換Android (記錄)
下一篇
Day20-學習[Building for iOS with Flutter]IOS 轉換Android (記錄)
系列文
基礎學習Flutter30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言