如何在MacOS中安装两种不同版本的飞镖以用于颤振和渡槽

问题描述

目前,我安装的飞镖装有颤振,版本如下:

Flutter 1.23.0-18.1.pre • channel beta • https://github.com/Flutter/Flutter.git
Framework • revision 198df796aa (2 weeks ago) • 2020-10-15 12:04:33 -0700
Engine • revision 1d12d82d9c
Tools • Dart 2.11.0 (build 2.11.0-213.1.beta)

我主要从事Mobile App前端开发,因此此设置对我来说很有益。

但是对于后端数据库开发,我开始学习Aqueduct(https://aqueduct.io/docs/getting_started/)。我注意到渡槽3.3.0 + 1(这是渡槽的当前稳定版本)仅适用于dart

因此,我想知道是否可以在Mac中安装两个版本的dart。 如果可以,我该怎么办? 以及当我分别或同时使用它们时,如何切换或选择不同版本的飞镖和aquedart飞镖?

编辑:之所以这样做,是因为运行aqueduct create project时出现错误。有解决办法吗?

-- Aqueduct CLI Version: 3.3.0+1
*** Uncaught error
    Bad state: No element
  **** Stacktrace
  * #0      ListMixin.firstWhere (dart:collection/list.dart:150:5)
  * #1      CLIAqueductGlobal.aqueductPackageRef (package:aqueduct/src/cli/commands/create.dart:342:10)
  * #2      CLIAqueductGlobal.templateDirectory (package:aqueduct/src/cli/commands/create.dart:347:12)
  * #3      CLIAqueductGlobal.getTemplateLocation (package:aqueduct/src/cli/commands/create.dart:351:12)
  * #4      CLITemplateCreator.handle (package:aqueduct/src/cli/commands/create.dart:51:27)
  * #5      CLICommand.process (package:aqueduct/src/cli/command.dart:159:20)
  * <asynchronous suspension>
  * #6      CLICommand.process (package:aqueduct/src/cli/command.dart:135:12)
  * #7      main (file:///C:/Users/dos/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/aqueduct-3.3.0+1/bin/aqueduct.dart:9:27)
  * #8      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
  * #9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
  ****

解决方法

这不是事实。 Aqueduct和Flutter处理pubsbpec.yaml中低于3.0.0的Dart版本

我和我的兄弟在一个开发项目中,并且正在将其与最新的渡槽一起使用

import React,{ Component,useEffect,useState } from 'react';
import { View,KeyboardAvoidingView,TextInput,Text,Platform,TouchableWithoutFeedback,Keyboard,ActivityIndicator,SafeAreaView,ScrollView,Button,StatusBar } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator,useHeaderHeight } from '@react-navigation/stack';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
import { useSafeAreaInsets,SafeAreaProvider } from 'react-native-safe-area-context';

const Stack = createStackNavigator();

function TicketStack() {
  return (
    <Stack.Navigator
      screenOptions={{
        headerStatusBarHeight: 0,// Header had increased size with SafeArea for some reason (https://github.com/react-navigation/react-navigation/issues/5936)
        headerStyle: { 
          backgroundColor: "dodgerblue",elevation: 0,// remove shadow on Android
          shadowOpacity: 0,// remove shadow on iOS
        },headerTintColor: "#fff",headerTitleStyle: {
          fontWeight: "900",fontSize: 26,},}}>
      <Stack.Screen name="Ticket">
        {(props) => <TicketScreen {...props} />}
      </Stack.Screen>
      <Stack.Screen name="Chat">
        {(props) => <ChatScreen {...props} />}
      </Stack.Screen>
    </Stack.Navigator>
  );
}

function HomeScreen() {
  return (
    <View style={{ flex: 1,alignItems: 'center' }}>
      <Text><FontAwesome5 name={"home"} size={20} color={"dodgerblue"} />Home screen</Text>
    </View>
  );
}

function TicketScreen(props){
  return (
    <View style={{ flex: 1,justifyContent: 'center',alignItems: 'center' }}>
      <Text>Ticket screen</Text>
      <Button title="Go to Chat" onPress={() => props.navigation.navigate('Chat')} />
    </View>
  );
}

function CustomKeyboardAvoidingView({ children,style }) {
    const headerHeight = useHeaderHeight();
    console.log("headerHeight: " + headerHeight)
    console.log("StatusBar.currentHeight: " + StatusBar.currentHeight)

    const insets = useSafeAreaInsets();
    const [bottomPadding,setBottomPadding] = useState(insets.bottom)
    const [topPadding,setTopPadding] = useState(insets.top)

    useEffect(() => {
      // This useEffect is needed because insets are undefined at first for some reason
      // https://github.com/th3rdwave/react-native-safe-area-context/issues/54
      setBottomPadding(insets.bottom)
      setTopPadding(insets.top)

      console.log("topPadding: " + topPadding)
      console.log("bottomPadding: " + bottomPadding)
    },[insets.bottom,insets.top])

    return (
        <KeyboardAvoidingView
            style={style}
            behavior={Platform.OS == "ios" ? "padding" : "height"}
            keyboardVerticalOffset={headerHeight + topPadding + StatusBar.currentHeight}
        >
            {children}
        </KeyboardAvoidingView>
    );
}

function ChatScreen(){
  return(
      <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
        <CustomKeyboardAvoidingView style={{backgroundColor: "#fff",flex: 1,flexDirection: "column",justifyContent: "space-between" }}>
          <View style={{backgroundColor: "dodgerblue",paddingVertical: 15}}>
              <View style={{ margin: 10,marginBottom: 15}}>
                  <ActivityIndicator size="large" style={{marginBottom: 10}}/>
                  <Text>Waiting for more info here....</Text>
              </View>
          </View>

          <ScrollView style={{backgroundColor: "tomato",paddingVertical: 15}}>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
              <Text>Chat messages</Text>
          </ScrollView>
          
          <View style={{backgroundColor: "yellow",paddingVertical: 15}}>
              <TextInput placeholder="Type your message here..." />
          </View>
        </CustomKeyboardAvoidingView>
      </TouchableWithoutFeedback>
  )
}

const Tab = createBottomTabNavigator();

export default class App extends Component {
  render(){
    return (
      <SafeAreaProvider>
        <SafeAreaView style={{flex: 1,backgroundColor: "dodgerblue"}}>
          <NavigationContainer>
            <Tab.Navigator
              screenOptions={({ route }) => ({
                tabBarIcon: ({ color,size }) => {
                  let iconName;

                  if (route.name === 'Home') {
                    iconName = 'home';
                  } else if (route.name === 'Ticket') {
                    iconName = 'question';
                  }
                  return <FontAwesome5 name={iconName} size={size} color={color} />;
                },})}
              tabBarOptions={{
                style: {
                  height: 70
                },activeTintColor: "#fff",inactiveTintColor: "dodgerblue",inactiveBackgroundColor: "#fff",activeBackgroundColor: "dodgerblue",tabStyle: {
                  paddingTop: 10,paddingBottom: 10,height: 70
                },labelStyle: {
                  fontSize: 14
                },keyboardHidesTabBar: (Platform.OS == "ios" ? false : true)
              }}>
              <Tab.Screen name="Home">
                {(props) => <HomeScreen {...props} />}
              </Tab.Screen>
              <Tab.Screen name="Ticket">
                {(props) => <TicketStack {...props} />}
              </Tab.Screen>
            </Tab.Navigator>
          </NavigationContainer>
        </SafeAreaView>
      </SafeAreaProvider>
    );
  }
}

您无需担心flutter的dart sdk,它可以单独处理

要使用除颤振之外的新飞镖,只需使用Homebrew

Flutter (Channel master,1.24.0-4.0.pre.138,on Mac OS X 10.15.7 19H2
    darwin-x64,locale en-BR)

在您的flutter项目中,您使用新的dart路径在.vscode文件夹中的settings.json中进行了覆盖(我使用的是flutter_master构建,因此我也不得不覆盖它而不是稳定的flutter)

brew tap dart-lang/dart
brew install dart

更新1:

使用以下命令更新您的pubspec.yaml

{
  "dart.flutterSdkPath": "~/Library/flutter_master/bin","dart.sdkPath": "/usr/local/bin/dart"
}

您提到的错误对我来说也是一样,我忘了提及。 我很久以前在this github thread

中发现的问题 ,

我在运行aqueduct create project时遇到EDIT时遇到的问题是由于首先没有正确设置发布。

如果您遇到此问题,请利用

  1. 将dart-sdk插入路径环境变量。有关更多信息,请遵循此链接https://www.youtube.com/watch?v=VdcJ2PAzXWs&ab_channel=NickManning的前几分钟。这使您可以使用pub
  2. 如果您已正确执行上述步骤,则可以运行pub global activate aqueduct NOT flutter pub global activate aqueduct,然后再创建项目而没有任何问题。