您当前的位置: 首页 >  flutter

大前端之旅

暂无认证

  • 2浏览

    0关注

    403博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

检查 Flutter 应用程序是否在 Web 上运行

大前端之旅 发布时间:2022-03-03 15:02:46 ,浏览量:2

您可以使用基础库中的kIsWeb常量检查您的 Flutter 应用程序是否在 Web 浏览器上运行 在这里插入图片描述

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        // Remove the debug banner
        debugShowCheckedModeBanner: false,
        title: '大前端之旅',
        theme: ThemeData(
          primarySwatch: Colors.indigo,
        ),
        home: const HomePage());
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('大前端之旅')),
      body: const Center(
        child: Text(kIsWeb ? 'Web' : 'Not Web',
            style: TextStyle(
              fontSize: 40,
            )),
      ),
    );
  }
}

关注
打赏
1660524863
查看更多评论
立即登录/注册

微信扫码登录

0.0413s