Home > OS >  How do I run a different part of a folder in flutter (VS Codium)
How do I run a different part of a folder in flutter (VS Codium)

Time:11-04

I have made a new file in my views folder but whenever I turn on the emulator and run the code, it just says "Hello World". Is there a way I can set the starting point of the project to be on this new file? Because it only seems to turn on the main.dart file.

This is the code that is in the views file called home_page.dart . It is supposed to just say "Hi" 10 times.

import 'package:flutter/material.dart';

import '../models/post.dart';

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

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<Post>? posts;
  var isLoaded = false;

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

    //fetch data from API
    getData();
  }

  getData() async {
    // posts = await
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Posts'),
      ),
      body: ListView.builder(
        itemCount: 10,
          itemBuilder: (context, index) {
            return Container(
            child: Text('Hi'),
            );
        },
      )
    );
  }
}

CodePudding user response:

in flutter the main.dart file is the first file

import 'package:flutter/material.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
     
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),//add your home page here
    );
  }
}
  • Related