HarmonyOS 如何点击一个按钮之后再进入flutter ?

HarmonyOS 如何点击一个按钮之后再进入flutter ?

HarmonyOS
2024-11-26 08:58:31
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

使用条件语句进行判断渲染。

struct Index { 
  private context = getContext(this) as common.UIAbilityContext 
  @LocalStorageLink('viewId') viewId: string = ""; 
  @State isFlutterPage:boolean = false; 
 
  build() { 
    Column() { 
      if (this.isFlutterPage) { 
        FlutterPage({ viewId: this.viewId }) 
      } else { 
        Button('跳转').width(50).height(50).onClick(()=> { 
          this.isFlutterPage = true; 
        }) 
      } 
    }.justifyContent(FlexAlign.Center).width('100%').height('100%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

路由跳转。

import router from '@ohos.router'; 
@Entry 
@Component 
struct Index { 
  build() { 
    Column() { 
      Button('跳转').width(50).height(50).onClick(()=> { 
        router.pushUrl({ url: 'pages/FlutterPageIndex' }) 
      }) 
    }.justifyContent(FlexAlign.Center).width('100%').height('100%') 
  } 
} 
  
FlutterPageIndex 页面 
 
import { FlutterAbility } from '@ohos/flutter_ohos'; 
export default class EntryAbility extends FlutterAbility { 
 
} 
 
@Entry 
@Component 
struct FlutterPageIndex { 
 
  build() { 
    Column() { 
      FlutterPage() 
    }.width('100%').height('100%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
分享
微博
QQ
微信
回复
2024-11-26 16:11:29
相关问题
如何设置一个通知按钮
1134浏览 • 1回复 待解决