我最近运行了这个命令来在 Flutter 中尝试 Web 支持:
flutter config --enable-web
Run Code Online (Sandbox Code Playgroud)
现在,我制作的每个项目都有一个web文件夹,里面有一个index.html. 有什么方法可以为将来的项目禁用它,我删除文件夹并继续操作是否安全?
我正在使用googleapi的 Flutter 包,要使用 Google Drive API,我需要输入凭据。我的问题是,如何将它们安全地存储在我的应用程序中,以便在我发布应用程序时无法使用它们。我找到了一个很酷的包flutter_secure_storage但要使用它,我需要将所有值放入安全存储中。那我该怎么做呢?我想使用类似的这样,但我不知道。如果有人能把我放在正确的方向上,如何通过这本书来做到这一点,那就太好了。
进一步解释一下,我不想将我的敏感信息放在文件中,例如main.dart要放入存储的变量(如果它还没有的话)。
我正在使用 Visual Studio 代码和 Genymotion 作为设备。我也通过指定 Genymotion 上的路径将 Genymotion 与 VSCode 连接起来。\n但是当我运行代码时flutter run,它给了我一个错误:
Launching lib\\main.dart on 192.168.127.101:5555 in debug mode...\nRunning Gradle task 'assembleDebug'...\nRunning Gradle task 'assembleDebug'... Done 96.0s\n\xe2\x88\x9a Built build\\app\\outputs\\apk\\debug\\app-debug.apk.\nInstalling build\\app\\outputs\\apk\\app.apk... 4.1s\nError waiting for a debug connection: Bad state: No element\nError launching application on 192.168.127.101:5555.\nRun Code Online (Sandbox Code Playgroud)\n 我刚刚开始了解 slivers,除了那些以“Sliver”开头的小部件之外,它们似乎不能与任何其他 Flutter 小部件一起使用。我尝试添加一个,Container以便我可以添加BorderRadius来装饰列表。但我收到了这个错误:
RenderSliverFillRemaining 需要 RenderBox 类型的子代,但收到 RenderSliverToBoxAdapter 类型的子代。
到目前为止,这是我的代码:
...
SliverFillRemaining(
child: SliverToBoxAdapter(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(36),
topRight: Radius.circular(36),
),
),
child: SliverPadding(
padding: const EdgeInsets.all(16),
sliver: SliverFixedExtentList(
itemExtent: 50.0,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.lightBlue[100 * (index % 9)],
child: Text('List Item $index'),
);
},
),
),
),
),
),
),
...
Run Code Online (Sandbox Code Playgroud) 如何升级我的 Flutter dev_dependencies?该flutter pub upgrade命令似乎不适用于这些命令,并且我没有看到--dev该命令的参数,所以我是否必须手动更新它们,或者我做错了什么?
我正在使用get_it包,你有两个选项来注册单例,lazy 和我猜是“常规”(GetIt.instance.registerLazySingleton和GetIt.instance.registerSingleton分别)这是注册为普通单例的类之一:
class AndroidDetails {
static final DeviceInfoPlugin _deviceInfoPlugin = DeviceInfoPlugin();
Map<String, dynamic> _deviceData = {};
AndroidDetails() {
_init().then((_) => getIt.signalReady(this));
}
Future<void> _init() async {
try {
AndroidDeviceInfo _deviceInfo = await deviceInfoPlugin.androidInfo;
_deviceData = _getDeviceData(_deviceInfo);
} on PlatformException {
_deviceData = <String, dynamic>{
'Error:': 'Failed to get platform version.',
};
}
}
Map<String, dynamic> _getDeviceData(AndroidDeviceInfo build) {
return <String, dynamic>{
'version.sdkInt': build.version.sdkInt,
};
}
bool canChangeStatusBarColor() {
if (_deviceData.isNotEmpty) {
return _deviceData['version.sdkInt'] >= …Run Code Online (Sandbox Code Playgroud) 我正在建立一个系统,当用户将系统主题更改为暗模式时,它会更改主题,并且使用 Flutter,它运行良好!但是,当用户更改系统主题时,系统导航和状态栏不会改变它们的颜色。我在 build 方法内的主页上运行了代码,但似乎没有这样做。这是主页构建方法中的代码:
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Brightness sysBrightness = MediaQuery.of(context).platformBrightness;
if (sysBrightness == Brightness.dark)
Themes.setDarkSystemColors();
else
Themes.setLightSystemColors();
return Scaffold(
appBar: CustomAppBar(title: "Home"),
drawer: CustomDrawer(),
body: SizedBox(),
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是主应用程序中带有theme:和的代码darkTheme::
return MaterialApp(
initialRoute: '/',
routes: routes,
navigatorObservers: [_routeObserver],
theme: Themes.lightTheme,
darkTheme: Themes.darkTheme,
debugShowCheckedModeBanner: false,
title: 'School Life',
);
Run Code Online (Sandbox Code Playgroud) 我希望能够将 aColor转换为List<int>[0,255,255] 之类的。
我怎么做?
我需要在我的应用程序中保存切换开关的状态并在开始时加载它。为此,我使用SharedPreferences:
Future<bool> saveSwitchState(bool value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool("switchState", value);
return prefs.setBool("switchState", value);
}
Future<bool> getSwitchState() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
isSwitchedFT = prefs.getBool("switchState");
print(isSwitchedFT);
return isSwitchedFT;
}
Run Code Online (Sandbox Code Playgroud)
每次更改切换值时都会运行 saveSwitchState() 。
问题出在应用程序的启动处。我创建了一个 bool 值:bool isSwitchedFT = false;
我用 false 初始化,因为 null 会给我错误。我如何isSwitchedFT = getSwitchState;
为 isSwitchedFT 设置 On 空值,它可以编译,但我的模拟器上出现红色错误:
'package:flutter/src/material/toggleable.dart': Failed assertion: line 45 pos 15: 'tristate || value
!= null': is not true.
Run Code Online (Sandbox Code Playgroud)
当使用值进行编译时,开关可以正常工作并保存更改的值。
Switch(
value: isSwitchedFT,
onChanged: (bool value) …Run Code Online (Sandbox Code Playgroud) 我格式化了我的电脑并将 flutter sdk 位置保留在同一位置。唯一的区别是用户文件夹的名称。以前叫“thesl”,现在叫“bscho”。每当我去构建我的 flutter 应用程序时,我都会得到以下信息:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Failed to create parent directory 'C:\Users\thesl' when creating directory 'C:\Users\thesl\OneDrive\dev\redlino\redlino\android\app\build\intermediates\flutter\debug\flutter_assets'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Exception: Gradle task assembleDebug failed with exit code 1 …Run Code Online (Sandbox Code Playgroud) 为什么此代码不起作用并且未显示底部工作表。我也试过运行代码,但它仍然不起作用。我想在单击按钮时在颤动中显示模态底部工作表。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void startInputAction(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (_) {
return Container(
height: 200,
padding: EdgeInsets.all(10),
child: Text("Something"),
);
},
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Error Practice Bottom Sheet"),
backgroundColor: Colors.purple,
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
color: Colors.purple,
padding: EdgeInsets.all(20),
child: Text("Click here"), …Run Code Online (Sandbox Code Playgroud)