Flutter —— 左右切换视图

turboksFlutter64

Simulator Screen Shot - iPhone 12 - 2022-05-09 at 14.49.50.png






import 'package:flutter/material.dart';
import 'package:ks/pageone.dart';
import 'package:ks/pagetwo.dart';

class TestPage extends StatefulWidget {
@override
_FriendsListState createState() => _FriendsListState();
}

class _FriendsListState extends State<TestPage>
with SingleTickerProviderStateMixin {
    late TabController _tabController;

    @override
    void initState() {
    super.initState();

    _tabController = TabController(initialIndex: 0, length: 2, vsync: this);
}

@override
void dispose() {
    super.dispose();
    _tabController.dispose();
}

@override
Widget build(BuildContext context) {
    return DefaultTabController(
    length: 2,
    child: Scaffold(
    appBar: AppBar(
    toolbarHeight: 80,
    title: Column(
    children: [
        Container(
            width: MediaQuery.of(context).size.width,
            height: 40,
            child: Text("拍立送"),
            alignment: Alignment.center,
        ),
        Container(
            height: 40,
            alignment: Alignment.topLeft,
            child: TabBar(
            tabs: [
                Tab(text: '全球精选'),
                Tab(text: '拍立送'),
            ],
            controller: _tabController,
            indicatorWeight: 3,
            indicatorPadding: EdgeInsets.only(left: 10, right: 10),
            labelPadding: EdgeInsets.symmetric(horizontal: 10),
            isScrollable: true,
            indicatorColor: Color(0xffFF7E98),
            labelColor: Color(0xffFF7E98),
            labelStyle: TextStyle(
            fontSize: 25,
            color: Color(0xffFF7E98),
            fontWeight: FontWeight.w500,
        ),
        unselectedLabelColor: Color(0xffAAAAAA),
        unselectedLabelStyle:
        TextStyle(fontSize: 20, color: Color(0xffAAAAAA)),
        indicatorSize: TabBarIndicatorSize.label,
    )),
    ],
    ),
    elevation: 0,
    ),
    body: TabBarView(
    children: [
    Container(
    child: PageOne(),
    ),
    Container(
    child: PageTwo(),
    ),
],
controller: _tabController,
),
),
);
}
}



相关文章

Flutter —— 轮播图

Flutter —— 轮播图

1.pubspec.yaml  flutter_swiper: ^1.1.6 # 轮播图2.自定义一个类import 'package:flutter/material.dart&#...

Flutter —— 使用RGB颜色

Flutter —— 使用RGB颜色

import 'dart:ui';extension HexColor on Color {  /// String is in the format "aabbc...

Flutter —— 网络请求

Flutter —— 网络请求

1.pubspec.yamldio: ^3.0.9 #网络请求2.使用    var url = "urlurlurlurlurl";   ...

Flutter —— 原生交互

Flutter —— 原生交互

一:传递数据flutter:var methodChannel = const MethodChannel("ksapp");onPressed: () {// sendToAnd...

Flutter —— TabBarView每次进入都刷新?

Flutter —— TabBarView每次进入都刷新?

import 'package:flutter/material.dart';class PageOne extends StatefulWidget {const PageOne({...

Flutter —— 路由

Flutter —— 路由

1. pubspec.yamlfluro: ^1.5.1 #路由2. 路由管理中心    // ignore: import_of_legacy_library...